473,785 Members | 3,352 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem creating PNG from Byte Array in J2ME

For different reasons I am reading an array of bytes from a file in my
..jar-file and from this I want to create a PNG image using
Image.createIma ge(myArray, 0 , myArray.length) .

I had a prototype that did this and it worked fine. It was working on
a file with a series of PNG-images just thrown together, one after
another, the MIDlet read the bytes of each image in turn into an array
of bytes that was then used to create the image.

But I hade to process the images some more, reducing colors and create
palette (PLTE chunk) manually. So now the file looks something like
this:
IHDR-chunk
PLTE-chunk
IEND-chunk
and then any number of
IDAT-chunks
the IDAT chunks are PNG IDAT chunks as in the PNG specification. What
I do (to save space obviously) is I read the different chunks into
separate arrays and the put them together to create an image, JUST as
in the first prototype.

I have also written a small tester for all of this that reads the
abovementioned file in the EXACT same way the MIDlet does and puts the
bytes together in the EXACT same way as the MIDlet does and then just
writes them to a file. This file then... it is a valid PNG-image. I've
even run pngcheck on it and it's just fiine!

The error I get when doing all of this (Image.createIm age(myArray, 0 ,
myArray.length) ) is:

java.io.EOFExce ption

at java.io.DataInp utStream.readFu lly(DataInputSt ream.java:268)

at com.sun.kvem.pn g.PNGImageReade r.decodePass(Un known Source)

at com.sun.kvem.pn g.PNGImageReade r.decodeImage(U nknown Source)

at com.sun.kvem.pn g.PNGImageReade r.readImage(Unk nown Source)

at com.sun.kvem.pn g.PNGImageReade r.read(Unknown Source)

at com.sun.kvem.mi dp.GraphicsBrid ge.loadImage(Un known Source)

at com.sun.kvem.mi dp.GraphicsBrid ge.createImageF romData(Unknown
Source)

at sun.reflect.Nat iveMethodAccess orImpl.invoke0( Native Method)

at sun.reflect.Nat iveMethodAccess orImpl.invoke(N ativeMethodAcce ssorImpl.java:3 9)

at sun.reflect.Del egatingMethodAc cessorImpl.invo ke(DelegatingMe thodAccessorImp l.java:25)

at java.lang.refle ct.Method.invok e(Method.java:3 24)

at com.sun.kvem.Li me$Connection.c allMethod(Unkno wn Source)

at com.sun.kvem.Li me$Connection.p rocessCommand(U nknown Source)

at com.sun.kvem.Li me$Connection.r un(Unknown Source)

at java.lang.Threa d.run(Thread.ja va:534)

Might this be a problem with "Adler checksum"? I knew about the CRC
checksums and I generate these from the data and they are working fine
(otherwise the image wouldn't work anywhere else). The Alder checksums
are only related to the IDAT chunks and the deflate algorithm and I
thought these were written in the zlib stream, not outside of the
stream. This checksum is NOT specified in the PNG specification in the
Chunk Layout for instance, only mentioned in brief with regards to the
zlib stream. No algorithm is presented why this leads me to believe
(considering the images actually work everywhere else but in my
program...) that it is of no consequence to my problem.

I have also written a small tester, as mentioned above, that generates
a PNG-file which works. What I did today was adding code in my MIDlet
that loads a PNG-image from a file and tested it using two images, one
generated by some other program and one generated by my test-app.

The one I have generated gives me the exact same error message. This
leads me to believe that something after all is wrong with these
pictures, something that pngcheck fails to register and that NO OTHER
APP in the entire free world cares about...

//Tommie
Jul 17 '05 #1
2 15083
For everyones information I solved this problem just a couple of hours
later. The problem was, of course, that the image was corrupted in
some way. What happened was that I in my application that creates the
IHDR chunk stated that the image hade 96 lines when in fact it only
had 71. That pngcheck didn't react to this is seriously strange. What
happened, I realize now, is that all other applications just read the
image and displayed it in 96x96 and somehow just stretching the image
data to 96 lines. Image.createIma ge is not as forgiving though...

I discovered this by the filter byte information in pngcheck's output.
It gives you the filter type for each scanline (0-5 or whatever) and
in my case it just output 71 (the number of actual lines) of 96. All
other images seemd to have filters for each row (in fact they have to
according to the spec) specified...

Anyways, thanks for your time, hope this gives any pointers to you
people out there.

//Tommie
Jul 17 '05 #2
pradeepunair
2 New Member
hi friends
i am a newbie in j2me. i was trying to retrieve multiple images on the client side from a servlet. the servlet fetches the images, converts them into bytes and encodes them using base64.
on the client side it decodes and then again converts it back to byte array. the problem is that it shows an illegal argument exception upon converting it back to image by using the createImage() function.
could you please help me with this problem. :) :(
Apr 23 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
8389
by: Bo | last post by:
Hi I have an array of int that represents a frame buffer, which I update dynamicly. Each int is 0xAARRGGBB. In standard java I can use imageProducer to create an Image object. In J2ME there is only createImage( Byte, int,int,int) in the Images class. From reading past posts it seems the Byte array must adhere to some PNG format (which I have no idea). In other words, I can't use a Byte array equivalent of my int array.
0
2991
by: RJS | last post by:
Hi all, I can't get a py2exe compiled app to run with numarray (numarray-0.5.win32- py2.2). Also wxPythonWIN32-2.3.3.1-Py22 and ActivePython-2.2.1-222. In the sample below, commenting out "import numarray" allows the exe to run. Left in, I get "4.exe has generated errors" etc. I'm going around and around and there isn't much on Google. py2exe output is last.
6
683
by: Club-B42 | last post by:
i've compiled my programm using command "python setup.py py2exe >1" python script works fine, but .exe version fails with ===================================================================== D:\\Scripts\B-4-2\la2luncher\dist>la2launcher.exe Traceback (most recent call last): File "la2launcher.py", line 9, in ? File "config.pyc", line 11, in ? File "config.pyc", line 8, in u LookupError: no codec search functions registered: can't find...
38
3544
by: jrlen balane | last post by:
basically what the code does is transmit data to a hardware and then receive data that the hardware will transmit. import serial import string import time from struct import * ser = serial.Serial()
0
285
by: crawlerxp | last post by:
This is the problem: I do not get the output I need when encoding and decoding data using rijndael alghoritm. Look at the code and see what the problem is actually: Please paste this code into your Visual Studio and compile it + run it; so you can see what the actual problem is. Thanks. code:
4
6715
by: Terry | last post by:
I'm building some dll assemblies that have in them the implementation of an abstract class defined in a different assembly. I'm trying to create objects of the type defined in the dlls with "Activator.CreateInstance". Everything was working fine until I started to fill out the class def with some implementation. At some point the CreateInstance was failing with a "MissingMethodException - No parameterless constructor defined for this...
11
6639
by: Abhishek | last post by:
I have a problem transfering files using sockets from pocket pc(.net compact c#) to desktop(not using .net just mfc and sockets 2 API). The socket communication is not a issue and I am able to transfer data across.On the serve I am using Socket 2 API (recv function to read bytes)and not using ..NET. I use FileStream to open the file on the pocket pc, then associate a BinaryReader object with the stream and call ReadBytes to read all the...
26
4840
by: Olaf Baeyens | last post by:
I am trying to port some C++ structures to C# but I have troubles with this one. Note: this is a file record, so I must keep this format. #pragma pack( push, 1 ) typedef struct { char title; DWORD dwCount; } STLHEADER, *LPSTLHEADER;
8
10719
by: intrepid_dw | last post by:
Hello, all. I've created a C# dll that contains, among other things, two functions dealing with byte arrays. The first is a function that returns a byte array, and the other is intended to receive a byte array as one of its parameters. The project is marked for COM interop, and that all proceeds normally. When I reference the type library in the VB6 project, and write the code to call the function that returns the byte array, it works
0
10315
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10085
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9947
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7494
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5379
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.