Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Edges in image are not smooth after setpixels in android

I am using getpixels() and setpixels() api. From Bitmap using getpixel api getting one by one pixel and doing some modification and setting the pixel, doing this operation for all pixels in a loop. I could see same alpha value for all pixels not able to find the reason. Please suggest a solution. Please find the attached image to see the issue

                   int width, height;
           height = bmpOriginal.getHeight();
           width = bmpOriginal.getWidth(); 

            int[] pix = new int[width * height];
            bmpOriginal.getPixels(pix, 0, width, 0, 0, width, height);



            int R, G, B, A; 


            float[] hsv = new float[3];
            float[] hsv2 = new float[3];
            float[] hsv3 = new float[3];



            for (int y = 0; y < height; y++){
            for (int x = 0; x < width; x++)
            {
                int index = y * width + x;
                R = (pix[index] >> 16) & 0xff;     //bitwise shifting
                G = (pix[index] >> 8) & 0xff;
                B = pix[index] & 0xff;            


                Color.RGBToHSV(R, G, B, hsv);                   

                int value = tempBitmap.getPixel(x, y);


               Color.colorToHSV(value, hsv2);                           

                int x = Color.HSVToColor(hsv3);
                pix[index] = x;


                }

            }  

            bmpOriginal.setPixels(pix, 0, width, 0, 0, width, height);
like image 268
pavan Avatar asked Nov 03 '22 23:11

pavan


1 Answers

Use setAntiAlias(true) api on your paint object to turn on anti aliasing. Also try setFilterBitmap(true) on paint.

Make a BitmapDrawable out of your bitmap. Then, call mBmpdrawable.setAntiAlias(true); before using it. Also try calling mBmpdrawable.setFilterBitmap(true)

like image 67
Ronnie Avatar answered Nov 08 '22 12:11

Ronnie