【问题标题】:Change color of image using pixel changes in android studio在 android studio 中使用像素变化来改变图像的颜色
【发布时间】:2021-12-08 03:41:31
【问题描述】:

我正在尝试将图像的颜色更改为红色或任何其他我编写了以下代码的颜色,但是在运行我的应用程序后,我的模拟器中不会发生任何事情 我的代码是

public class MainActivity extends AppCompatActivity {

int x=0,y=0;
ImageView imViewAndroid,displayimg;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    imViewAndroid = (ImageView) findViewById(R.id.imViewAndroid);
    displayimg = (ImageView) findViewById(R.id.setimageview);

    Bitmap bitmap = ((BitmapDrawable)imViewAndroid.getDrawable()).getBitmap();
    int pixel = bitmap.getPixel(x,y);

    for(int i=0;i<imViewAndroid.getWidth();i++){
        for(int j=0;i<imViewAndroid.getHeight();j++)
        {
             pixel=bitmap.getPixel(i,j);
             bitmap.setPixel(i,j,Color.RED);
            displayimg.setImageBitmap(bitmap);
        }

    }

我的模拟器显示这个benter image description here

我的重点是得到这个结果 enter image description here

【问题讨论】:

    标签: java android-studio bitmap imageview pixel


    【解决方案1】:

    实现这一目标的一种方法是使用ColorFilter

    ColorFilter overlay = new PorterDuffColorFilter(Color.YELLOW, PorterDuff.Mode.OVERLAY);
    Drawable drawable = imageView.getBackground();
    drawable.setColorFilter(overlay);
    imageView.setBackground(drawable);
    

    【讨论】:

    • 但是亲爱的我没有使用 ColorFilter 请检查我的代码并提出建议
    • @CodingWithHammad 您想要的图像不是通过逐个像素操作来轻松实现的。 24 位有 16,777,216 种颜色变化。让系统来处理。
    • 那我该怎么办?帮帮我
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-15
    • 2019-11-19
    • 2014-12-24
    • 1970-01-01
    相关资源
    最近更新 更多