You Are Here:

Community: Developer Discussion Boards

Reply « Previous Thread | Next Thread »

#1 Old Creating ,saving and reading the new image in Mobile phones - 2009-03-18, 19:00

Join Date: Mar 2009
Posts: 15
veenit33
Offline
Registered User
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
Reply With Quote

#2 Old Re: Creating ,saving and reading the new image in Mobile phones - 2009-03-18, 19:42

Join Date: Jun 2003
Posts: 4,335
Location: Cheshire, UK
grahamhughes's Avatar
grahamhughes
Offline
Forum Nokia Champion
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.
Reply With Quote

#3 Old Re: Creating ,saving and reading the new image in Mobile phones - 2009-03-19, 11:32

Join Date: Mar 2009
Posts: 15
veenit33
Offline
Registered User
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..?
Reply With Quote

#4 Old Re: Creating ,saving and reading the new image in Mobile phones - 2009-03-19, 15:03

Join Date: Jun 2003
Posts: 4,335
Location: Cheshire, UK
grahamhughes's Avatar
grahamhughes
Offline
Forum Nokia Champion
How do you get the byte[]?
Reply With Quote

#5 Old Re: Creating ,saving and reading the new image in Mobile phones - 2009-03-20, 15:37

Join Date: Mar 2009
Posts: 15
veenit33
Offline
Registered User
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...
Reply With Quote

#6 Old Re: Creating ,saving and reading the new image in Mobile phones - 2009-03-20, 15:45

Join Date: Jun 2003
Posts: 4,335
Location: Cheshire, UK
grahamhughes's Avatar
grahamhughes
Offline
Forum Nokia Champion
First, though I'm sure it's not a problem, I think:

Code:
byte[] newImageData = new byte[imageData.length + CHUNK_SIZE];
should read:

Code:
byte[] newImageData = new byte[imageData.length + readAmount];
In fact, if you know the size in advance, you can reduce the whole thing to:

PHP Code:
byte[] imageData = new byte[overallSize];
int readAmount 0;
while (
readAmount overallSize) {
    
readAmount += fis.read(imageDatareadAmountoverallSize readAmout);

Anyway... what this reads in not RGB or ARGB values. It's a PNG file. How are you modifying this?

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.
Reply With Quote

#7 Old Re: Creating ,saving and reading the new image in Mobile phones - 2009-03-20, 15:59

Join Date: Mar 2009
Posts: 15
veenit33
Offline
Registered User
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?
Reply With Quote

#8 Old Re: Creating ,saving and reading the new image in Mobile phones - 2009-03-20, 16:14

Join Date: Jun 2003
Posts: 4,335
Location: Cheshire, UK
grahamhughes's Avatar
grahamhughes
Offline
Forum Nokia Champion
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.
Reply With Quote

#9 Old Re: Creating ,saving and reading the new image in Mobile phones - 2009-03-21, 07:48

Join Date: Mar 2009
Posts: 15
veenit33
Offline
Registered User
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..!!!!!
Reply With Quote

#10 Old Re: Creating ,saving and reading the new image in Mobile phones - 2009-03-21, 11:05

Join Date: Jun 2003
Posts: 4,335
Location: Cheshire, UK
grahamhughes's Avatar
grahamhughes
Offline
Forum Nokia Champion
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:
Image img Image.createImage("/somefile.png");

// get image dimensions
int width img.getWidth();
int height img.getHeight();
// create an array large enough for all pixels in the image
int[] pixels = new int[width height];
// grab the pixel data
img.getRGB(pixels0width00widthheight); 
"pixels" now contains the ARGB values for the image. Each pixel is represented by an int. The 32 bits of each int are as follows:

Code:
        AAAAAAAA RRRRRRRR GGGGGGGG BBBBBBBB
So, eight bits of each alpha, red, green and blue. For example, to get the red component for the pixel at (x,y):

PHP Code:
int red = (pixels[(width) + x] >> 16) & 0xff
You can create an Image object from this as:

PHP Code:
Image newImage Image.createRGBImage(pixelswidthheighttrue); 
The last parameter is "processAlpha"... use "false" if you want to ignore the alpha values in the pixel data.

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.
Reply With Quote

#11 Old Re: Creating ,saving and reading the new image in Mobile phones - 2009-03-21, 12:19

Join Date: Mar 2009
Posts: 15
veenit33
Offline
Registered User
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
Reply With Quote

#12 Old Re: Creating ,saving and reading the new image in Mobile phones - 2009-03-21, 13:16

Join Date: Jun 2003
Posts: 4,335
Location: Cheshire, UK
grahamhughes's Avatar
grahamhughes
Offline
Forum Nokia Champion
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.
Reply With Quote

#13 Old Re: Creating ,saving and reading the new image in Mobile phones - 2009-03-21, 13:38

Join Date: Mar 2009
Posts: 15
veenit33
Offline
Registered User
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?
Reply With Quote

#14 Old Re: Creating ,saving and reading the new image in Mobile phones - 2009-03-21, 13:53

Join Date: Jun 2003
Posts: 4,335
Location: Cheshire, UK
grahamhughes's Avatar
grahamhughes
Offline
Forum Nokia Champion
You should just need to add that source file to your project.
Reply With Quote

#15 Old Re: Creating ,saving and reading the new image in Mobile phones - 2009-03-21, 13:57

Join Date: Mar 2009
Posts: 15
veenit33
Offline
Registered User
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 With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
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

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia