ImageIO JPEG strange colors

61 views
Skip to first unread message

State Thirteen

unread,
Nov 17, 2013, 5:26:01 PM11/17/13
to codenameone...@googlegroups.com
Hi,

I am using ImageIO to scale the image and to get a byte array for displaying it in WebBrowser. 

img = Image.createImage(input);
img = img.scaledWidth(300);

ImageIO imio = Display.getInstance().getImageIO();
ByteArrayOutputStream os = new ByteArrayOutputStream();

try {
        imio.save(img, os, ImageIO.FORMAT_JPEG, 1.0f);
     String encodedImg = WebBrowser.createDataURI(os.toByteArray(), mimeMap.get("JPG"));

} catch (IOException e) {
e.printStackTrace();
}

This is the result what i get in WebBrowser

If I save the image in PNG everything is ok.

I have tested it only on simulator though.  


Shai Almog

unread,
Nov 18, 2013, 1:37:47 AM11/18/13
to codenameone...@googlegroups.com
Hi,
odd. I would guess its a Java bug on the simulator. Since the ImageIO implementation for devices is radically different I wouldn't worry too much about it.
Which Java version/OS are you using?

State Thirteen

unread,
Nov 18, 2013, 3:03:44 AM11/18/13
to codenameone...@googlegroups.com
I am using Java 1.7 on win 7. What is you advice about which format is better to use on phones? Is it a big difference between PNG and JPEG? 

Shai Almog

unread,
Nov 18, 2013, 1:24:29 PM11/18/13
to codenameone...@googlegroups.com
For photos always go with JPG but I wouldn't go with your approach to scaling.
There is a second version of ImageIO save that accepts scaling arguments and is more efficient since it uses native scaling where applicable.

State Thirteen

unread,
Nov 18, 2013, 1:30:05 PM11/18/13
to codenameone...@googlegroups.com
Thanks. I'll try this.

Jonata Russi

unread,
Dec 18, 2013, 12:14:46 PM12/18/13
to codenameone...@googlegroups.com
Hi, State

Managed to solve?

State Thirteen

unread,
Dec 18, 2013, 12:21:20 PM12/18/13
to codenameone...@googlegroups.com
Hi Jonata,

I think this is an emulator, browser or JRE issue because on real devices there is no such problem.

On Wednesday, December 18, 2013 9:14:46 PM UTC+4, Jonata Russi wrote:
Hi, State

Managed to solve?
Reply all
Reply to author
Forward
0 new messages