简体   繁体   English

更改图像颜色的一部分

[英]change part of image color

in my app, i want to change text color in below image, when user clicked each word , i have position of each words in data base and draw a rectangle with canvas.drawRect but i want to change exactly color of texts in my ImageView: 在我的应用程序中,我想更改下面图像中的文本颜色,当用户单击每个单词时,我在数据库中确定了每个单词的位置,并使用canvas.drawRect绘制了一个矩形,但我想更改ImageView中文本的确切颜色: 在此处输入图片说明

my code in Imageview is : 我在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);

    }
}

at last i crop a part of my imageview,change color it and draw this with canvas: (onDraw) 最后,我裁剪了我的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);

method changeBitmapColor 方法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;
}

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM