converting an image using createRGBImage()

Hi all,

I’m having a few problems processing my images. I’ve got the following method that takes an image and creates a int array to hold all the pixel values. This seems to work fine, but it is when I need to recreate an image from this data that is posing a problem:

Image processImage(Image src) {
int w = src.getWidth();
int h = src.getHeight();

int[] pixels = new int[w*h];
src.getRGB(pixels,0,w,0,0,w,h);

// The following line seems to be throwing illegal argument exceptions:
Image dest = Image.createRGBImage(pixels, w, h, true);

return(dest);
}

I’ve tried to use the DirectGraphics and DirectUtils methods to draw the pixels but this results in Illegal State Exceptions.

Any help on this matter would be much appreciated! It should be simple, but I’m not sure where I’m going wrong.

Regards,

ribot

I wrote a quick test MIDlet to do this. It worked fine in the Wireless Toolkit and in the S60 Concept SDK emulator. However, it locked up my S60 & S80 phones so that both needed the batteries taking out to restart them :(. I’ve reported the, um, ‘undocumented feature’ to the guilty parties, but for now you may be out of luck…

Thanks for the feedback David!

I have found that it also locks my Nokia S60 emulator, and when locking in the phone the only way to reset is as you say to take the battery out. :frowning: Very scary.

I’ve played around with a few other things - I can get the method to work as long as the length of pixels is short enough. e.g. works at 5000 length with w = 176 and h = 30, but crashes at anything more.

I’m a bit surprised that no one has come across this before?

Regards,

ribot.

The only temporary solution I have come up with is as follows. Basically, this method takes an image and returns an int[] array of pixel data with the alpha value amended.

int[] getRGBDataFromImg(Image src, int hexAlphaValue) {

int w = src.getWidth();
int h = src.getHeight();
int nPixels = w*h;

int[] pixels = new int[nPixels];
int[] srcPixels = new int[nPixels];
src.getRGB(srcPixels,0,w,0,0,w,h);

int tmpPixel;
for(int i=0; i<nPixels.length; i++) {
tmpPixel = srcPixels[i];
pixels[i] = hexAlphaValue | (tmpPixel & 0xff0000) | (tmpPixel & 0xff00) | tmpPixel & 0xff;

}

return(pixels);

So, I now having to temporarily use drawRGB() to draw 36600 pixels every frame which to say the least is quite slow! :confused: Could anyone offer any optimisations? If anyone knows a way around the createRGBImage bug I would be most grateful if you could post.

Regards,

ribot

Wish I could help, but I’m not having much luck. I tried using the Nokia UI API, i.e.:


Image newImage = DirectUtils.createImage(width, height, 0x00000000);
newImage.getGraphics().drawRGB(data, 0, width, 0, 0, width, height, true);

but my S60 phone hung in exactly the same way - it’s probably implemented on top of the same bug.

Since you say it works with smaller images, would you be able to create several smaller horizontal slice images and draw them? Not pretty, but it might do the job.

I had thought about breaking up the one large image into 8 smaller ones, I’ll conduct some more tests this afternoon. Is there a known generic place on the web that contains a list of known bugs for nokia devices and some type of form to submit newly discovered bugs?

Many thanks for your help!

ribot

ribot dude what are you doing in the JME mumble? get
back to web-sites and jogl u minx! ;D

Mixing J2ME, JSP and Servlets (work) with Jogl and Cocoa (personal). :smiley:
What are you up to these days? You must have some handy hints for image processing optimisation lying around? :smiley:

ribot

[quote]Is there a known generic place on the web that contains a list of known bugs for nokia devices and some type of form to submit newly discovered bugs?
[/quote]
I don’t know of one. Forum Nokia publishes a document called ‘Known Issues in the Nokia 6600 MIDP 2.0 Implementation’ that is certainly worth reading. If you want to report a bug to Nokia, probably the best place would be Forum Nokia’s discussion groups. If you join Forum Nokia Pro (costs $$$s) you’ll have better channels for communicating with Nokia.

Ok, thanks. I’ll download a copy of ‘Known Issues in the Nokia 6600 MIDP 2.0 Implementation’. I’ve been searching various forums and websites and it just seems strange that very few have come across the same problems. Maybe they know better to not play with the createRGBImage function. :smiley:

Many thanks for your help.