在我的应用中,我想更改下面图像中的文本颜色,当用户单击每个单词时,我在数据库中具有每个单词的位置,并用canvas.drawRect
绘制一个矩形,但我想更改的确切颜色我的ImageView中的文字:
我在Imageview中的代码是:
@Override
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
Paint paint = new Paint();
paint.setColor(Color.parseColor("#5DFFF700"));
paint.setStyle(Paint.Style.FILL_AND_STROKE);
if (highlight) {
float rightx = thisL.maxX/scale;
float leftx = thisL.minX/scale;
float bottomy = thisL.maxY/scale;
float topy= thisL.minY/scale;
canvas.drawRect(leftx, topy, rightx, bottomy, paint);
}
//slctd word
if (slctdWord!=null) {
paint.setStyle(Paint.Style.FILL_AND_STROKE);
float wrightx = slctdWord.max_x / scale;
float wleftx = slctdWord.min_x / scale;
float wbottomy = slctdWord.max_y / scale;
float wtopy = slctdWord.min_y / scale;
canvas.drawRect(wleftx, wtopy, wrightx, wbottomy, paint);
}
}
答案 0 :(得分:0)
最后,我裁剪了我的imageview的一部分,将其更改颜色并用画布绘制: (onDraw)
Bitmap bm=((BitmapDrawable)getDrawable()).getBitmap();
Bitmap crdb = changeBitmapColor(Bitmap.createBitmap(bm,
Math.round(leftx), Math.round(topy), Math.round(rightx-leftx),Math.round(bottomy-topy)));
canvas.drawBitmap(crdb,leftx,topy,null);
方法changeBitmapColor
public Bitmap changeBitmapColor(Bitmap sourceBitmap)
{
Bitmap resultBitmap = sourceBitmap.copy(sourceBitmap.getConfig(),true);
Paint paint = new Paint();
ColorFilter filter = new LightingColorFilter(Color.WHITE, Color.RED);
paint.setColorFilter(filter);
Canvas canvas = new Canvas(resultBitmap);
canvas.drawBitmap(resultBitmap, 0, 0, paint);
return resultBitmap;
}