|
Post by tomcruise on Jun 1, 2008 3:53:16 GMT -5
|
|
|
Post by tomcruise on Jun 1, 2008 4:01:04 GMT -5
|
|
|
Post by Adam Schmelzle on Jun 1, 2008 7:23:31 GMT -5
The problem with the 'black' edges, is likely because it's not 'alpha blending'. It's probably treating all non-zero alpha values as if they were 100% opaque. Is it correct to assume that the source image for the bubble has semi-opaque pixels in it?
So the goal here is to draw the bubbles/buttons ontop of another 'background' image, but when we're done the 'background' image needs to have the areas around the bubbles be transparent right?
So to accomplish this, I'd...
1) Make the background image 2) fill the backround image with red: 0xff0000 3) draw the bubbles/buttons on top of the background image 4) get a copy of the background image where the remaining 'red' pixels are all transparent. Use a function like this, where the 2 parameters are the (backgroundImage, 0xff0000);
public static Image getImageCopyWithTransparentBackground(Image img, int transparentColor){ int imgW = img.getWidth(); int imgH = img.getHeight(); int[] rGB = new int[imgW * imgH]; img.getRGB(rGB, 0, imgW, 0, 0, imgW, imgH); for(int i=0; i < rGB.length; i++){ if( (rGB[i] & 0x00ffffff) != transparentColor){ rGB[i] = rGB[i] | 0xff000000; }else{ rGB[i] = 0x00ffffff & transparentColor; } } Image copy = (Image.createRGBImage(rGB, imgW, imgH, true)); //copy.getGraphics().setFont(img.getGraphics().getFont()); //Runtime.getRuntime().gc(); return copy; } }
If this doesn't help, than I must be misunderstanding the problem. We'll get it worked out eventually.
|
|
|
Post by Adam Schmelzle on Jun 1, 2008 7:25:16 GMT -5
Code tags suck in this board system.
|
|
|
Post by tomcruise on Jun 2, 2008 2:16:41 GMT -5
hey dude,
i got an idea, it will work like this without any issue .. and it is the perfect solution. look ! read the pixsel of base image, and read the pixels of top image, and set the top image pixel according to desired x,y in base image ... this will work .. i'm d**n sure...
tell me how can i read image pixels in two dimentional array [x][y]. please send me small example
thanks Tomcruise
|
|
|
Post by tomcruise on Jun 2, 2008 2:17:15 GMT -5
without using graphics oject .. we have to solve this problem dude
|
|
|
Post by tomcruise on Jun 2, 2008 2:17:37 GMT -5
i hope you got my idea ...
|
|
|
Post by tomcruise on Jun 2, 2008 4:42:46 GMT -5
how can i draw/replace a pixel on specific pixel postion of the some image. i'm looking for some algorithm thourgh which i can do this...
|
|
|
Post by Adam Schmelzle on Jun 2, 2008 7:33:53 GMT -5
I don't understand what my solution is lacking, since it works for me all the time.
You can't alter the pixels of an image in J2ME. You just can't. You can get a copy, like you already know how to do, and then create a new image. You just can't change an image directly.
You will not be able to find a solution if you expect to be able to make changes after setting the transparency, it just can't be done.
|
|
|
Post by tomcruise on Jun 2, 2008 13:08:13 GMT -5
dude your solutions is fine, but in that it black edges on the bubble image are still there i dont know why ... do u have some sample images so i can see... 2nd approach:but once i draw image using graphics object and then change the pixel, image lost its transparency... dude, we have image pixels of both images, can't we replace or alter ?
|
|
|
Post by Adam Schmelzle on Jun 2, 2008 13:27:14 GMT -5
As I said, we can change the data in the array, and create a new image using the altered data, but you can't alter the underlying image data directly.
I've mentioned this already, but are you using in-between alpha values? The phone may not be capable of handling the alpha blending, and is likely just using simple bit masking. You won't have black edges if you use strictly fully-opaque and fully-transparent pixels in the original image. The black edges are likely because your source image has semi-transparent black pixels around the edge that are being treated as fully transparent in the midlet.
Maybe you could post the images that you are working with? It's unfortunate that we don't have the same amount of control over the clipping/blending as we do in J2SE.
If you really need blended pixels, you can manually do the blending of course. You can use averages of the target and source, based on the weight of the alpha value of the source. You'll just have to do it all using the pixel arrays, and then create a new image when you are done.
|
|