java-me,png,emulator,photoshop,wtk , J2ME - PNG created in PhotoShop not displaying in emulator

J2ME - PNG created in PhotoShop not displaying in emulator


Tag: java-me,png,emulator,photoshop,wtk

My midlet is showing some images fine, but not others.

They are all 8-bit PNGs, but the ones that aren't displaying are the ones I have created myself in PhotoShop.

So I am thinking maybe my PhotoShop (CS6) settings are wrong...

PNG-8, Selective, Diffusion, Colors: 256, Dither: 100%, Matte: None, Web Snap: 0%, Convert to sRGB: ticked, Width: 48, Height: 48, Percent: 100%, Quality: Bicubic.

I've experimented with a few of these settings, but to no avail.

Any ideas?

There is a similar problem here but this is opposite to mine in that PhotoShop mends things in that case, rather than breaks things...

My code is...

image = Image.createImage("/img/loading1.png");

...and here is my stack trace:
    at com.sun.kvem.png.PNGImageReader.parse_iTXt_chunk(
    at com.sun.kvem.png.PNGImageReader.readMetadata(
    at com.sun.kvem.png.PNGImageReader.readImage(
    at com.sun.kvem.midp.GraphicsBridge.loadImage(
    at com.sun.kvem.midp.GraphicsBridge.createImageFromData(
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(
    at java.lang.reflect.Method.invoke(
    at com.sun.kvem.sublime.MethodExecution.process(
    at com.sun.kvem.sublime.SublimeExecutor.processRequest(
    at javax.microedition.lcdui.Image.createImage(

The image in question does exist - both in the project and in the jar that is built.

Here is the image in question: enter image description here


According to the crash log, the PNG decoder in J2ME fails inside the non-critical chunk iTXt:1

> com.sun.kvem.png.PNGImageReader.readMetadata
  > com.sun.kvem.png.PNGImageReader.parse_iTXt_chunk

According to libpng documentation, the text part of an iTXt chunk must be valid UTF8:

... The remaining chunk data is the main UTF-8 text, either zlib-compressed or not, according to the compression flag. Since its length can be determined from the chunk length, it is not null-terminated. As with the other two text chunks, newlines should be represented by single line-feed characters (decimal 10), and all other control characters (1-9, 11-31, and 127-159) are discouraged.

and so normally this would indicate that the stream read is not valid UTF8 text - it contains 'raw' bytes higher than the plain ASCII range 0..127 that do not conform to UTF8 rules.

I found that not to be the case in the sample image. There is only one set of consecutive bytes that form a UTF8 code sequence, and it is a valid one:

<?xpacket begin="EFBBBF" id=" ..

(the bolded section represents 3 data bytes in hexadecimal notation). I first suspected this was the error:

If the BOM character appears in the middle of a data stream, Unicode says it should be interpreted as a "zero-width non-breaking space" (inhibits line-breaking between word-glyphs). In Unicode 3.2, this usage is deprecated in favour of the "Word Joiner" character, U+2060.[1] This allows U+FEFF to be only used as a BOM.

.. and so a fully conforming UTF8 reader should inspect its bytes and throw an UTFDataFormatException when it encounters a BOM anywhere else than as the very first value. Surprisingly, this does not seem to be the problem! First of all, there is no indication any of the readUTF sources do anything else than only verify if the UTF8 code is valid on its own, irrespective of its value. There are lots of 'invalid' Unicode code points (values that do not represent a valid Unicode character or instruction), but it appears to me they are all silently ignored. But I noticed the common readUTF functions only implement a small subset of UTF8/Unicode (see, e.g., Modified UTF-8 in Oracle's documentation).

So the problem lies elsewhere. Another clue to this is that the error thrown is not UTFDataFormatException but rather EOFException, indicating the read buffer ran out of the number of bytes it was promised to contain.

(warning: pure conjecture follows)

Looking at a source of DataInputStream, I find this snippet of code:

588       public final static String readUTF(DataInput in) throws IOException {
589           int utflen = in.readUnsignedShort();

followed by a loop to read utflen bytes (not "Unicode characters"). This is wrong for an iTXt chunk, as it does not have a 'first word' to indicate its length. The number of bytes in the plain text can be derived from the chunk length (which is, per PNG convention, the total data length excluding the length long word, the iTXt signature itself, and the final CRC32 code) minus the length of the zero-terminated keyword name, language, and "translated keyword" strings, and the two bytes which indicate compression of the full plain text.

As a work-around, remove the iTXt chunks from your PNG images. The data itself -- XMP Metadata -- is most likely not interesting at all for your purposes (but feel free to read what benefits Adobe thinks it has). And if your workflow does not use it, it's just a useless hunk of uncompressed text, taking up 814 bytes of the total of 981 bytes in your sample image -- a whopping 83%!

You can use an external utility to remove extraneous data chunks; the command line for the popular pngcrush, for example, is

pngcrush -rem alla -rem text InputFile.png OutputFile.png


Or directly from Photoshop: if you save a PNG 'the usual way' with the "Save As" menu option, the metadata goes in and there is no checkbox to get rid of it. If you use "Save for Web & Devices" instead, you get a large dialog with a lot of handy options, such as a drop down list labelled "Metadata".

Choosing "All" I got an even larger file; my version of Photoshop creates a massive 3K chunk of XMP Metadata, including a 2K totally empty 'filler' block...
Selecting "Copyright" or "None" finally got rid of all the crud (presumably because I did not fill in any copyright information), and then you get a nice 169 bytes long PNG, in which the only metadata is that software used is called "Adobe ImageReady".

1 Which is kind of ironic. Per PNG specifications,

.. A decoder encountering an unknown chunk in which the ancillary bit is 1 can safely ignore the chunk and proceed to display the image.

This "ancillary bit" is the 5th bit of the first byte of the chunk ID: 0 (uppercase) = critical, 1 (lowercase) = ancillary, i.e., if the first character of the chunk ID is a capital, a PNG reader must read and interpret its data correctly, and if it's not, it can be skipped silently.

So technically, the writers of J2ME could safely have ignored this entire chunk. But they messed it up, attempt to read it, and now the code crashes on all programs that merely try to read the image data in PNGs which happen to contain iTXt chunks.


Use image Button with transparent color area

I have a picture in PNG with transparent and normal color. I use this for one Button: this.Button1.BackColor = System.Drawing.Color.Transparent; this.Button1.BackgroundImage = Image; this.Button1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None; this.Button1.FlatAppearance.BorderSize = 0; this.Button1.FlatAppearance.MouseDownBackColor = System.Drawing.Color.Transparent; this.Button1.FlatAppearance.MouseOverBackColor = System.Drawing.Color.Transparent; this.Button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;...

Why does PNGing an image from a JPG make it 10x bigger?

I have an image captured via webcam of my cat (the subject might not be important). I've aquired it as a 31 kB JPG file. When I open it with an image editor, then save it (without alteration) as a PNG (max. compression) it stores as a 297 kB file....

Letter 'j' bugged with imagettftext function

I've created a script to generate an avatar by using PHP and all work fine but when there is the letter j in $data1['username'], the letter erase a part of the previous letter. NOTE : I use calibri bold italic (Downloaded here) This is my code : $image = imagecreatefrompng("avatar.png");...

Calling number with special characters in J2ME Nokia

I want to call a number in the below format using platformRequest: platformRequest("tel:number,number#number#"); But i'm getting an invalid number error , is it possible to do that?...

How I can get the Base64 data after converting div to img?

I am not expert in javascript I wanted to convert div to image then I found this jsfiddle $(function() { $("#btnSave").click(function() { html2canvas($("#widget"), { onrendered: function(canvas) { theCanvas = canvas; document.body.appendChild(canvas); // Convert and download as image Canvas2Image.saveAsPNG(canvas); $("#img-out").append(canvas); // Clean up //document.body.removeChild(canvas); } }); }); }); but how I...

Skip bytes in ByteArray Java

My app reads a png-like file (in byte) and stores bytes into a byteArray. This is the method I use : public static byte[] read(File file) throws IOException { byte []buffer = new byte[(int) file.length()]; InputStream ios = null; try { ios = new FileInputStream(file); if ( == -1...

Nokia Asha SDK files

This is a very unusual request but since M$ took down the Nokia wiki pages, I can't seem to find some two files am looking for, namely [][1] [][2] I'd deeply appreciate it if someone would share their copy. Thanks....

worklight server preview wont show png resources anymore after configuring it to serve svg

I ran in the problem where svg images were not loading using WorkLight preview. I found the solution for that here: How can I configure Worklight to serve *.svg files with contentType=image/xml+svg? After adding these lines <mimeTypes> <type>svg=image/svg+xml</type> </mimeTypes> svg files appeared on preview, but now i can't load png...

I cannot set the AM_PM variable in Java 8 Micro Edition

I'm a teaching myself Java and am a beginner. As part of a larger project I am running code to determine, and then later set, the time on a Calendar object. I have scoured the internet for a way to set the AM_PM value but I cannot get it to...

Generate overlay map image from geo data

I need to generate a transparent image to apply on map similar to these: Image_1or Image_2 I need to generate this image from a dataset: I have many data points (with lat and long) and I would to generate this image (server side) to show density on map of my...

Exporting png/svg as a single png file using PHP

So basically I have use SVG/javascript/PHP so that when a user clicks on a PNG image it takes the coordinates and uses these to plot a small black square on the PNG image, it's really very simple. However, I was wondering if it's possible if you have the PNG in...

C++ Bitmap Resource (RT_BITMAP) and PNG Image Format

An application I'm developing displays various PNG images to the user in a window, and it works fine. My question is more on the grounds on HOW my PNG's are stored in the PE. Currently, the PNG's are stored in the executable as a resource, under the RT_RCDATA Resource Type,...

Large repeating background image in Internet Explorer

I'm trying to have an oversized image within a viewport container presented as a background image with a repeat style on it. The below code works for Chrome and Firefox, but when looking at it in Internet Explorer (observed in 9 and 11 on multiple machines), I'm getting an odd...

Sending png file via socket in Python

I'm using python version 2.7.9 and i try to send png file. But something strange happens..i using sockets and sends a post request(or kind of). I send the request to the server from the client,then i prints the length of the request received on the server, for example, the length...

PNG transparent backgrounds appearing black when using Android Studio

The social icons below (for fb, twitter, mail and share) are circular PNGs with transparent backgrounds. When I use the code and exact same images in Eclipse, I get transparent background but when build and run with Android Studio, I get black backgrounds. See details below. Images are the same....

PHP GD How to circular crop 3 square images and merge into 1 image maintaining transparency

I have 2 source images and I want to: Do a circular crop of each image, with the outside of the circle transparent Merge/copy all images back onto a destination transparent image. I have tried many examples, but can't seem to maintain transparency on the final image. I'm trying to...

Png Image instead of Text in PHP [closed]

Hello i want to show a png image instead of text in my php file for my site. My Code: function format_age($t) { if ($t<30) return "LIVE"; return sprintf("%d%s%d%s%d%s", floor($t/86400), ' Tage ', ($t/3600)%24,' Std. ', ($t/60)%60,' Min.'); } So instead of "LIVE" i want to show an png Image....

PHP: PNG readfile encoding issue

I have this code which outputs a PNG file to the browser header('Content-type: image/png'); header("Content-Length: " . filesize($cache_file)); readfile($cache_file); exit(); The file $cache_file was saved like this imagepng(self::$image, self::$cache); The browser is displaying a broken image. When I download it and open it with npp, I find that it's encoded...

How to Convert PSD into PNG, using Python Wand / ImageMagick?

I tried converting PSD to PNG, but as I save the PNG, Wand (wand-0.4.0-py2.7) spits out all layers inside the PSD as separate PNG files (the last file saved is the one I want). So how to correctly convert from PSD to PNG? # Convert a large PSD to small...

Game Multi-Images Android

I have seen a lot of developer use all asset or images or drawable needed into one file png like this : the question is how can developer split each image to use it in android ? and what's advantage of this technique ? ...

Trouble downloading PNG images in Android

I am facing a problem downloading PNG images from my server to my Android app. The problem is specific to PNG images (JPG works fine), and the issue is that the downloaded files are corrupt images. I will explain in more details, below. Scenario : I need to download JPG...

Recompile R with PNG support

I am running R 3.1.2 on a headless Raspberry Pi 2 with Raspbian. Packages install fine, but I can't save PNGs. After googling the error for a long time, I found this response, which says I need to "manually recompile R with explicit PNG support." I apologize if this is...

Uploading PNG to Website Server

I have seen loads of other topics and I've tried them all. Can someone please help with why this script won't upload PNG files? Blank PNG image being displayed. $image = $_FILES['file']['tmp_name']; $image_name = $_FILES['file']['name']; $ext = pathinfo($image_name, PATHINFO_EXTENSION); $location = "Profiles/{$user}/Picture/{$image_name}"; $new_image = imagecreatetruecolor(100, 100); $source_image = imagecreatefrompng($image); imagealphablending($source_image,...

PNGImage “Access violation” error at procedure end

I am using PNGImage library in my project, which entire GUI is made up of .png images, which i loaded to TImages at run-time. For some purposes i have to dynamically create plenty of components groups that are similar to each other. Every group consists of some TImages and have...

How can I create a clip to show the evolution of a network?

Through R I can generate the topology of a network at each t, where t = 2000. What is generated is a .png file for each t. Do you know a program (or a way) to use these .png files as "frames" to create a video of how the network...

What do these bytes do?

This is the hexdump of a black 1x1 PNG made in Gimp and exported with minimal information: 89 50 4E 47 0D 0A 1A 0A 00 00 00 0D 49 48 44 52 00 00 00 01 00 00 00 01 08 02 00 00 00 90 77 53 DE...

Transparent gif not transparent?

I downloaded a transparent png from, and I thought that if I placed this png on my html page, that has a gradient colored background, I would only see the icon (a down arrow in this case). Instead, however, I see the icon and a white(ish) box surrounding the...

python seqdiag file is big and can't be openned in other computer?

I have used seqdiag to generate sequence diagram, and it generates 3MB png file. It sounds great, right? But something wrong when I open it. When I open the file, appdata/local/temp has gained 3GB, and generates big files named ~PI*.tmp. After I send the png file to others, they can't...

Why the first byte of .png file is 0x89?

I am currently reading about PNG file format. It turns out that the first byte of the file is specified to be equal to 0x89. I am wondering what are the reasons of the value of that byte. What I've already learned about the format is that the first byte...

Error with PNG files extracted from iPhone app?

I extracted a photo folder from an iPhone app but all the PNG files in the folder are not viewable. I tried googling it up and then tried few apps that fix PNGs from iPhone, but none of them worked. One app even said that my files were NOT in...

Imagemagick convert tif to rgba16 png

So here is my source tif image: $ identify -verbose source.tif Image: Format: TIFF (Tagged Image File Format) Class: DirectClass Geometry: 512x512+0+0 Resolution: 72x72 Print size: 7.11111x7.11111 Units: PixelsPerInch Type: Palette Base type: TrueColor Endianess: MSB Colorspace: RGB Depth: 8-bit Channel depth: red: 8-bit green: 8-bit blue: 1-bit And I've...

Native PNG library on MacOSX (mavericks)

I need to build an application which can read PNG files. On MacOSX mavericks the libpng is not available anymore (see). Is there any other way to read PNG file on MacOSX (Cocoa / Carbon Framework...). I'd rather stay with the native framework than download and compile a local libpng....

How to encode IImageProvider as a PNG image?

Assuming I have a LumiaImagingSDK rendering chain setup, with a final IImageProvider object that I want to render, how do I encode that into a PNG image?

Rename a bunch of PNG images with “.jpg” extension to “.png”

So I have a folder with thousands of image files, all of them saved as .jpg. The problem is that some of those files are actually PNG image files, so they don't open in a lot of programs, unless I manually change their extension to .png. For example, the Ubuntu...

Date Issue in J2ME

Straight to the point with this one. Let's say the date today is 16-06-2015 and the device date matches this. I'm trying to read it in this format, 16062015. However, the date is being shown to be one month behind i.e. 16052015. My code: public String getDate() { Calendar cal...

Consistent PNG Bit output with PHP Imagick

I have the following code to create a png swatch with a drop shadow (to dynamically insert in a PDF file using FPDF.) $shadowSwatch = $pm->clone() ; $shadowSwatch->setImageBackgroundColor('#000000') ; //Angle & Offset of Drop Shadow based on photoshop settings $angle = deg2rad(45) ; $xOffset = round(sin($angle) * 18, 0) ;...

SVG or PNG for html5 android game?

I created html5 android game. It uses simple ball which is device motion moved. For moving ball I use setinterval in javascript and change position for ball element. So what is better to use for better rendering and perfomance? SVG or PNG ball? And other elements in game, like coins,...

Compare images and remove duplicates

I have two folders with images, they're all PNGs. One folder is a copy of the other with some images changed and some added. The filenames are the same but the image contents may be different. Other attributes like time stamps are completely random, unfortunately. I want in the newer...

Wrong output size when plotting over an image in R

My goal is to read an image file in either the PNG or JPEG format and plot various data over said image and save it to disk. I also want the image to take up all available space in the produced plot, no axes or labels or anything. I'm a...

Converting 32x32 StdPicture icons to PNG

I am trying to convert an StdPicture into a PNG before encoding it to Base64 to be sent over XML. I've gotten the Base64 encoding portion down (see near end of function EncodeImageToBase64()) however I am having trouble converting the StdPicture object into a PNG byte array. Here's my function:...

C++ Opengl - How to load tgas and pngs in modern OpenGL? [on hold]

I am looking for a way to load tgas and pngs in C++ Opengl - I dislike the idea of using a library though. Is there any sample code / links / advice you could give me in this topic?...

Doing custom avatars with nodejs

So I'm wondering if this is also possible in nodejs. Basically I want to make a png out of several other pngs (all the same size) that are just stacked one over each other and then save it on the server. Can I do that? A short example would...

Why does Delphi XE7 change PNG image on every FMX form save?

I have a form with many custom firemonkey components where each contain multiple bitmaps (loaded from PNG image files). Every time the form is saved, the binary data of the PNG images change in the FMX file! This messes up my version control log (SVN), as changing just one property...

How can I convert PNG to GIF keeping the transparency?

How can I convert PNG to GIF keeping the transparency? I would have hoped that using the Assign( ) method would work but it doesn't seem to migrate transparency. In the GIF, it's represented as black. png:=TPngImage.Create; try png.LoadFromFile(sFile); // comes from file: png.TransparencyMode; // comes from file: png.Transparent //...

Xcode built-in png compression effects

I have a question about png-8 vs png-24 usage vs Xcode's built in "image compressor". Some images converted to png-8 are just fine saved like that, because difference between png-24 version can't be noticed easily. But some images have to be stored as png-24 so that quality remains at high...

Is there a way to measure the memory consumption of a PNG image?

I would like to know if there is a way in Python to measure the memory consumption of a PNG image. For my test I've to Images normal.png and evil.png. Let's say both images are 100kb in size. normal.png consists of data represented by 1 byte per pixel. evil.png consists...

RSA private Key decryption giving “InvalidCipherTextException” using bouncy castle

I am creating a encryption/decryption method using bouncy castle for j2me. I have created private / public keys using openssl and hard coding into the code. Encryption is working fine (I am getting encrypted string), but when I try decryption for that ciphertext I am getting below exception org.bouncycastle.crypto.InvalidCipherTextException: unknown...

How do I grep GZ files to extract PNG files?

Ok, so I have a tone of .GZ files in a folder, and I'm looking to recursively look through each one of them and extract all the PNG files into another destination folder. How would I do that? EDIT: I've been using this command from the terminal to find a...

Highcharts: overlapped columns in exported chart

The live chart looks fine, however, when exported to PNG, JPEG or PDF, the columns overlap. The code: exporting:{ chartOptions:{ legend:{ enabled:true, style: {fontFamily: "Arial"} }, } }, In addition, is there an option to change the font and size of the legend text in the export? I was...

Improve PNG optimization Gulp task

This is source PNG with transparency: (13.3kB) optimized using (5.4kB) optimized using (5.6kB) optimized with gulp-imagemin+imagemin-pngquant: (6.6kB) As you can see online tools are better than Gulp. Is there a way to improve PNG optimization with Gulp? Just in case, here's my gulp task:...