【问题标题】:My canvas.drawtext() doesn't work我的 canvas.drawtext() 不起作用
【发布时间】:2017-08-03 00:14:56
【问题描述】:

我有一个应用程序,我在其中使用 Canvas 进行数字签名。

画布效果很好,但我也想在画布上已经有一个文字,上面写着 - 签署于 DD:MM:YYYY, HH:MM。我知道如何使用日历并设置日期,但命令 canvas.drawtext() 不起作用。 任何想法我做错了什么?

PS - 其他一切都很好,我只想添加该文本。 :)

public class signature extends View {
        private static final float STROKE_WIDTH = 5f;
        private static final float HALF_STROKE_WIDTH = STROKE_WIDTH / 2;
        private Paint paint = new Paint();
        private Path path = new Path();

        private float lastTouchX;
        private float lastTouchY;
        private final RectF dirtyRect = new RectF();

        public signature(Context context, AttributeSet attrs) {
            super(context, attrs);
            paint.setAntiAlias(true);
            paint.setColor(Color.BLACK);
            paint.setStyle(Paint.Style.STROKE);
            paint.setStrokeJoin(Paint.Join.ROUND);
            paint.setStrokeWidth(STROKE_WIDTH);
            paint.setTextSize(100);



        }

        public void save(View v, String StoredPath) {
            Log.v("tag", "Width: " + v.getWidth());
            Log.v("tag", "Height: " + v.getHeight());
            if (bitmap == null) {
                bitmap = Bitmap.createBitmap(mContent.getWidth(), mContent.getHeight(), Bitmap.Config.RGB_565);
            }

            Canvas canvas = new Canvas(bitmap);

            canvas.drawText("Example text", 100, 100, paint);

            try {

                // Output the file
                FileOutputStream mFileOutStream = new FileOutputStream(StoredPath);
                v.draw(canvas);
                // Convert the output file to Image such as .png
                bitmap.compress(Bitmap.CompressFormat.PNG, 90, mFileOutStream);
                mFileOutStream.flush();
                mFileOutStream.close();



            } catch (Exception e) {
                Log.v("log_tag", e.toString());
            }
        }

【问题讨论】:

    标签: java android-canvas


    【解决方案1】:

    您正在文本之上绘制视图。

    将 v.draw(canvas) 改为 canvas.drawText 之前

    【讨论】:

      猜你喜欢
      • 2011-04-30
      • 2012-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-21
      • 2013-01-11
      • 2012-07-23
      相关资源
      最近更新 更多