| Reply | « Previous Thread | Next Thread » |
|
Hello
I am doing a J2ME project in which i am stuck up at one point I read Image from the phones memory,load it in memory. I modify the bits of this loaded image according to my need(I perform Image Steganography ) I want to save this new modified bits back to the memory as an image object. What happens is that i can save and create a new image but i cant read that new created image it gives me an Exception : javax.imageio.IIOException: Unknown row filter type (= 47)! at com.sun.kvem.png.PNGImageReader.decodePass(Unknown Source) at com.sun.kvem.png.PNGImageReader.decodeImage(Unknown Source) at com.sun.kvem.png.PNGImageReader.readImage(Unknown Source) at com.sun.kvem.png.PNGImageReader.read(Unknown Source) at com.sun.kvem.midp.GraphicsBridge.loadImage(Unknown Source) at com.sun.kvem.midp.GraphicsBridge.createImageFromData(Unknown Source) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at com.sun.kvem.sublime.MethodExecution.process(Unknown Source) at com.sun.kvem.sublime.SublimeExecutor.processRequest(Unknown Source) at com.sun.kvem.sublime.SublimeExecutor.run(Unknown Source) The code that i use to write image is Note: I read a .PNG image and i want to write a .PNG image back to phone memory public void save_image(byte[] imgData) { System.out.println("IMAGE DATA LENGTH : " + imgData.length); try { fc = (FileConnection) Connector.open("file:///root1/copy.png", Connector.READ_WRITE); if( !fc.exists() ) fc.create(); //System.out.println("FILE DATA 11 @@ : " + imgData.length); DataOutputStream dos=fc.openDataOutputStream(); //System.out.println("FILE DATA 22 @@ : " + imgData.length); dos.write(imgData, 0, imgData.length); dos.flush(); dos.close(); } catch(Exception e) { System.out.println("Exception : " + e); } finally { try { fc.close(); } catch (IOException ioe) { System.out.println(ioe); } } } U can contact me on veenitgshah@gmail.com Waiting for help.... Thanks in advance |
|
How do you "modify" the PNG? What is the source of the byte[] you are saving?
It sounds as if the PNG data you're saving is not valid. Cheers, Graham. |
| grahamhughes |
| View Public Profile |
| Find all posts by grahamhughes |
|
I hide text in the image...so i modify by inducing the bits of text at the lsb of each pixel...ie im performing Image Steganography
When i get the byte[] array of the PNG image does it have the ARGB format...? or do they have RGB..? |
|
How do you get the byte[]?
|
| grahamhughes |
| View Public Profile |
| Find all posts by grahamhughes |
|
FileConnection fc = (FileConnection)Connector.open("file://localhost/" + currDirName + fileName, Connector.READ);
if (!fc.exists()) { throw new IOException("File does not exists"); } // load the image data in memory // Read data in CHUNK_SIZE chunks InputStream fis = fc.openInputStream(); long overallSize = fc.fileSize(); int length = 0; while (length < overallSize) { byte[] data = new byte[CHUNK_SIZE]; int readAmount = fis.read(data, 0, CHUNK_SIZE); byte[] newImageData = new byte[imageData.length + CHUNK_SIZE]; System.arraycopy(imageData, 0, newImageData, 0, length); System.arraycopy(data, 0, newImageData, length, readAmount); imageData = newImageData; length += readAmount; } fis.close(); fc.close(); image = Image.createImage(imageData, 0,length); This is the code which loads the image file(bytes of image) on to the memory. i use this byte array named imageData in the last line to create a image object.. I can save the modified image but cant read it back from my application... can u give me ur email id so that i can mail u my code.. I need some urgent help... |
|
First, though I'm sure it's not a problem, I think:
Code:
byte[] newImageData = new byte[imageData.length + CHUNK_SIZE]; Code:
byte[] newImageData = new byte[imageData.length + readAmount]; PHP Code:
After you modify the data, are you still able to create an image from it? You need to use Image.getRGB() to get the RGB values from an image. Cheers, Graham. |
| grahamhughes |
| View Public Profile |
| Find all posts by grahamhughes |
|
yes i am able to modify the image and get a new image from it.
its a bit blurred but i can create a new file... i cant open this file from my application... this is my problem.. can u give me ur email id? |
|
Are you saying you modify the compressed PNG data? Or do you get the RGB values, modify those, then use your own PNG encoder?
I need to know exactly how you get the value of a pixel, modify it, and re-encode it. The error you have indicates that the PNG data you have is not valid. Either it has become damaged in the file i/o, or your process of image manipulation has not produced a valid image file. Cheers, Graham. |
| grahamhughes |
| View Public Profile |
| Find all posts by grahamhughes |
|
how do i know that the PNG data i have in my byte[] array is compressed or no?
the code i had pasted earlier i just pass the byte[] named imageData[] to a method which hides the bits of text. My question is can u list down the steps in order to get the PNG image file's data in byte array.? The steps which i do is i select the PNG image I load it in memory with the code i pasted earlier I then create a image object from the byte[] and use this byte[] to give it to the processing module... I need to know does the byte[] named imageData[] contains ARGB values? Should i use the getRGB() in order to get the RGB values in an int[] ..? if so then how do i convert this int[] back to byte[] ? I need some urgent help..!!!!! |
|
If you read the contents of a PNG file, what you get is a sequence of bytes, encoded as described in the PNG (Portable Network Graphics) Specification, Version 1.0.
If you want RGB values, you get them from an Image object like this: PHP Code:
Code:
AAAAAAAA RRRRRRRR GGGGGGGG BBBBBBBB PHP Code:
PHP Code:
Important: When you create an Image object, the pixel data will be converted into the device's internal format. This format will depend on the display hardware. The pixel array has 8 bits per channel (red, green, blue). A device with an 18 bit display uses only 6 bits per channel. Therefore, data in the lowest two bits of each channel will be lost. The result is: if you use createRGBImage(), then getRGB() from the image you create, you will not always get the same pixel data back. Your main problem then is, taking the int[] and encoding that into some file format. There is no easy way to do this. If you want to save a PNG, then you will need to find or write a PNG encoder. Cheers, Graham. |
| grahamhughes |
| View Public Profile |
| Find all posts by grahamhughes |
|
Now i have created image successfully back from the byte[].
this image[Stego Image ie on which i have performed Image Steganography] is the same in view as the original image. The problem is how do i save this image object. Suppose i have the image object in hand say Image new_img. How do i save this object in the phone memory? A code would be useful |
|
byte[] or int[]??
If you have an array of ARGB values, and you want to save it to a file in an image format (such as PNG), then you need code to convert the array of ARGB values into PNG format. I don't have code to give you that will do this. Using Google, I found someone who has written A minimal PNG encoder for J2ME. Maybe this is of help to you. Cheers, Graham. |
| grahamhughes |
| View Public Profile |
| Find all posts by grahamhughes |
|
how to use the PNG class which is there in that link?
should i paste it in the src folder of my project? Also can u express ur views as how to load a byte[] in main memory? |
|
You should just need to add that source file to your project.
|
| grahamhughes |
| View Public Profile |
| Find all posts by grahamhughes |
|
But then how do i save that image file in memory.
the output of that file is an Image object. I need to save this image object. How do i go on doing it? can u give me a code to save a file? |
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| Thread | Thread Starter | Forum | Replies | Last Post |
|---|---|---|---|---|
| Need Help regarding Application Development for Mobile Phones | SagarGupta | General Browsing | 7 | 2009-08-24 15:30 |
| How to get informations about an image without creating the Image Object | cristi.mota | Mobile Java Media (Graphics & Sounds) | 2 | 2008-06-27 09:47 |
| desperately needs help on how to save an image in the mobile device memory | daregazi | Mobile Java Media (Graphics & Sounds) | 1 | 2008-06-23 13:37 |
| Problem in build with S60 1FP | Manuelito_ | Symbian Tools & SDKs | 14 | 2007-09-18 13:08 |
| reading files from mobile phones | viraj_turakhia | Mobile Java General | 0 | 2005-01-04 13:46 |