tags:

views:

35

answers:

1

Friends, I have an andrid application to display an image on another. the second image's white colour should be converted in to transparent. so i used two imageviews. the original image to be overlayed is bitmap1. image after making transparent is bitmap2. when i run this i got some exceptios atsetPixel method. the code is shown below

Bitmap bitmap2 = null;
int width = imViewOverLay.getWidth();
int height = imViewOverLay.getHeight();
for(int x=0;x<width;x++)
{
    for(int y=0;y<height;y++)
    {
        if(bitMap1.getPixel(x, y) == Color.WHITE)
        {
            bitmap2.setPixel(x, y, Color.TRANSPARENT);
        }
        else
        {
            bitmap2.setPixel(x, y, bitMap1.getPixel(x, y));
        }
    }
}

imViewOverLay is the imageview of the over lay image. anybody please help me to know the mistakes in above code

A: 

The most obvious error is that you're not creating bitmap2 - unless you've not posted all the code of course.

You declare it and set it to null, but then don't do anything else until you try to call bitmap2.setPixel.

ChrisF
friends, i fixed the issue. removed bitmap2 and set the bitmap1 mutable.. let me know is there any method to speed up the loop operation?? in my application it takes a long time
asifkt
when i displayin above image.. it shows only the second(bitmap1);I need it to display on another bitmap(bitmap3). anybody plz help me with some hints. am using imageview to display image
asifkt
@asifkt - by necessity you have to loop over every pixel in the image, which will take a while if you have a large image. Either reduce the size of the image or use an image with a colour palette so you can just change a single value in the palette.
ChrisF
thank you chrisf, Can u help me to display a bitmap on another??. Already mentioned in above question that the second image to display on another image is transparent for specific colour
asifkt
asifkt - I'm not familiar with the Android display pipeline so I couldn't answer that I'm afraid.
ChrisF
ok, thanks..............
asifkt