| Author |
Converting RGB Byte [] to png image
|
Dushyant Chhetri
Ranch Hand
Joined: Oct 28, 2009
Posts: 75
|
|
Hi Fellow Ranchers
I am stuck amidst middle of my application and need help.
My application takes a snap and resizes the image so that we get a thumbnail and now the byte [] of this is converted into RGB byte [] so that I can save it to a record store by using Data Stream.
Now when I need to Retrieve this image I should be able to convert this RGB byte[] to png .
How do I convert this so that the png obtained will be of use to me.
|
 |
Gopinath Karyadath
Ranch Hand
Joined: Oct 14, 2009
Posts: 87
|
|
Hai
To get RGB Bytes from Image we Use
Image image = Image.createImage("/image.png") ;
int[] RGB = new int[image.getWidth() * image.getHeight()];
image.getRGB(RGB, 0, image.getWidth(), 0, 0, image.getWidth(), image.getHeight());
To Create Image From RGB Bytes .. try this
Image imagefromRGB ;
imagefromRGB = Image.createRGBImage(RGB, image.getWidth(), image.getHeight(), true);
Regards
Gopinath
http://j2me-codesamples.blogspot.com/
gopi@c2info.com
|
 |
Dushyant Chhetri
Ranch Hand
Joined: Oct 28, 2009
Posts: 75
|
|
Thanks for the response but
I have already tried it.
All I want to do is resize an image an save it in a record store and later get back the image.
What happens is I am getting an Image but the imag eis not the original, the image obtained is just a black patch.
|
 |
Gopinath Karyadath
Ranch Hand
Joined: Oct 14, 2009
Posts: 87
|
|
public Image createThumbnail(Image image, int reqwidth, int reqheight) {
int sourceWidth = image.getWidth();
int sourceHeight = image.getHeight();
int thumbWidth = reqwidth;
int thumbHeight = reqheight;
Image thumb = Image.createImage(thumbWidth, thumbHeight);
Graphics g = thumb.getGraphics();
for (int y = 0; y < thumbHeight; y++) {
for (int x = 0; x < thumbWidth; x++) {
g.setClip(x, y, 1, 1);
int dx = x * sourceWidth / thumbWidth;
int dy = y * sourceHeight / thumbHeight;
g.drawImage(image, x - dx, y - dy, Graphics.LEFT | Graphics.TOP);
}
}
Image immutableThumb = Image.createImage(thumb);
return immutableThumb;
}
try this to resize your image
Regards
Gopinath
gopi@c2info.com
|
 |
 |
|
|
subject: Converting RGB Byte [] to png image
|
|
|