How do I change the pixel color for a bitmap?

I have one bitmap object. When I use getpixel () on a bitmap and after setPixel on that bitmap object, then the pixel value (color) doesn't change. I am using an image to fill a color in a background image. The main problem is that I cannot fill the color above the color for the same area of ​​the image. When I filled a color over the image view then that area is not used to fill another color. This means I am not updating the filled color area of ​​the image. Below is my source code:

enter image description here

public static int DARK_PINK = Color.argb(255, 255, 51, 255);
    public static int LIGHT_YELLOW = Color.argb(255, 255, 230, 102);
    public static int DARK_MARUN = Color.argb(255, 148, 66, 50);
    public static int LIGHT_MARUN = Color.argb(255, 186, 123, 68);
    public static int RED = Color.argb(255, 252, 20, 20);
    public static int LIGHT_BLUE = Color.argb(255, 102, 255, 255);
    public static int DARK_BLUE = Color.argb(255, 70, 78, 202);
    public static int LIGHT_GREEN = Color.argb(255, 190, 255, 91);
    public static int DARK_GREEN = Color.argb(255, 15, 230, 0);
    public static int JAMBLI = Color.argb(255, 123, 0, 230);
    public static int ORANGE = Color.argb(255, 255, 187, 50);
    public static int BLACK = Color.argb(255, 7, 5, 0);
    public static int GRAY = Color.argb(255, 129, 128, 127);
    public static int PINK_RED = Color.argb(255, 255, 4, 139);
    public static int NEAVYBLUE = Color.argb(255, 51, 204, 255);
    public static int ADVANCE_GREEN = Color.argb(255, 102, 255, 204);

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

        setContentView(R.layout.activity_main);

Bundle extras = getIntent().getExtras();
        byte[] byteArray = extras.getByteArray("picture");

        bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);


        bitmap = bmp.copy(Bitmap.Config.ARGB_8888, true);
        canvas = new Canvas(bitmap);
        paint = new Paint();
        paint.setColor(DARK_PINK);
        paint.setAntiAlias(true);
        paint.setDither(true);
        paint.setStrokeWidth(30);
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeJoin(Paint.Join.ROUND);
        paint.setStrokeCap(Paint.Cap.ROUND);
        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OVER));
        // paint = new Paint(Paint.DITHER_FLAG);
        paths.add(path);
        path = new Path();

        image.setImageBitmap(bitmap);

        image.setOnTouchListener(this);


@Override
    public void onClick(View v) {
    switch (v.getId()) {

        case R.id.btn_color_one: {
    int pixel = DARK_PINK;

                bitmap.setPixel(x, y, pixel);
                if(pixel==DARK_PINK){
                    pixel = LIGHT_YELLOW;
                    bitmap.setPixel(x, y, pixel);
                    canvas = new Canvas(bitmap);

                }

                else{

                    Toast.makeText(getApplicationContext(), "Not Changed", 2).show();

                }
}
}
});
}

      

+3


source to share


1 answer


try assigning it a RGB color number like this



myBitmap.setPixel(x, y, Color.rgb(45, 127, 0));

      

0


source







All Articles