• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Converting RGB Byte [] to png image

 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



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
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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









 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic