本文介绍了帆布DrawText的定位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建一个绘图工具,在用户文本添加到图像。同时使文本通过绘制的帆布位置为位图没有被正确设置。
I am creating a drawing tool, where user add text to image. While making the text draw to bitmap via canvas position is not being set properly.
Paint paint = new Paint();
paint.setStyle(Paint.Style.FILL);
paint.setColor(Color.RED);
paint.setTypeface(tf);
paint.setTextAlign(Paint.Align.LEFT);
paint.setTextSize(30);
int xPos = layoutTextViewContainer.getLeft();
int yPos = layoutTextViewContainer.getTop();
canvas.drawText(text, xPos, yPos, paint);
画图
Rect textRect = new Rect();
paint.getTextBounds(text, 0, text.length(), textRect);
textRect.offset(0, -textRect.top);
Canvas canvas = new Canvas(bm);
layoutTextViewContainer持有编辑文本。
屏幕截图更多的澄清。
黑白文本编写和Red文字是图像嵌入的preVIEW
layoutTextViewContainer holds the edit text.Screen shot for more clarification.Black text is written and Red text is preview of embed in image
推荐答案
得到了解决。该值应像素独立
如下传递到之前的drawText转换XPOS和yPos
Got the solution. the values should be pixel independent convert xPos and yPos as below before passing to drawText
xPos = (int) (xPos / getResources().getDisplayMetrics().density);
yPos = (int) (yPos / getResources().getDisplayMetrics().density);
这篇关于帆布DrawText的定位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!