Results 1 to 7 of 7
- 03-02-2010, 04:05 PM #1
Member
- Join Date
- Mar 2010
- Posts
- 6
- Rep Power
- 0
problem with pixel values of an image
i am writing a code to encrypt/decrypt image files.
first i am reading pixel values from the source image
then converting it into alpha array,red array,green array,blue array
then after manipulating the arrays
i am writing the pixel values to get encrypted image
//i am printing the pixel values which i am writing to file
all is well till here(image gets encrypted)
but when i am reading the encrypted image again(for decryption)
the pixel values are different from what i have stored during encryption
as i am not able to read the original pixel values which were stored during encryption phase
i am not able to decrypt the image correctly
part of the code i am is attached
please help
- 03-04-2010, 05:26 PM #2
Member
- Join Date
- Mar 2010
- Posts
- 6
- Rep Power
- 0
no replies??
still facing the same problem....
- 03-04-2010, 05:29 PM #3
Member
- Join Date
- Mar 2010
- Posts
- 6
- Rep Power
- 0
do i need to move it to java 2d forum..
- 03-04-2010, 09:49 PM #4
Senior Member
- Join Date
- Feb 2010
- Location
- Ljubljana, Slovenia
- Posts
- 470
- Rep Power
- 4
The problem you are having, is that screen coordiantes and array indexes don't work the same way, if you have a table like this:
the position of the 1 would be expressed as following:Java Code:0,0,0,0 0,0,1,0 0,0,0,0
array index = table[1][2]
that is, 2nd row, 3rd collumn
on screen coordinates: 2,1
The gist of this is, in arrays, the first number represents which array to search in a 2d table (top to bottom), while the first number of on screen coordinates describes the amount of right shift (x coordinate). So, if you store image info in an array, be prepared for the fact that the array will need to be mirrored along the diagonal.
- 03-05-2010, 05:10 PM #5
Member
- Join Date
- Mar 2010
- Posts
- 6
- Rep Power
- 0
thanks for replying
i changed the code replaced i,j loops for getting the mirror values about diagonal
but still i am getting diiferent values for pixel when i read the file later.
code used for reading encrypted fileJava Code:int pixel; BufferedImage img=new BufferedImage(320, 240, BufferedImage.TYPE_INT_ARGB); // inter changed the i ,j loop for ( j = 0; j < 320; j++) { for ( i = 0; i < 240; i++) { System.out.println("x,y: " + j + ", " + i); pixel = (alphArray[j][i]<<24)|(redarray[j][i]<<16)|(greenarray[j][i]<<8)|bluearray[j][i]; //used 2d array for manipulation int alpha = (pixel >> 24) & 0xff; int red = (pixel >> 16) & 0xff; int green = (pixel >> 8) & 0xff; int blue = (pixel) & 0xff; System.out.println("argb: " + alpha + ", " + red + ", " + green + ", " + blue); //printing pixel values to check which values are bieng stored in file img.setRGB(j,i,pixel1); } } File f = new File("encrypt.jpg"); try { ImageIO.write(img, "jpg", f); } catch (IOException ex) { ex.printStackTrace(); }
Java Code:BufferedImage image = ImageIO.read(this.getClass().getResource("encrypt.jpg")); //reading file in decryption phase int w = image.getWidth(); int h = image.getHeight(); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { System.out.println("x,y: " + j + ", " + i); int pixel = image.getRGB(j, i); int alpha = (pixel >> 24) & 0xff; int red = (pixel >> 16) & 0xff; int green = (pixel >> 8) & 0xff; int blue = (pixel) & 0xff; System.out.println("argb: " + alpha + ", " + red + ", " + green + ", " + blue); //printed values are different from what i have stored during encryption phase
- 03-05-2010, 05:26 PM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,413
- Blog Entries
- 7
- Rep Power
- 17
Isn't the jpeg format a (lossy) compressed format of an image? If I'm correct that implies that the information is not written as you think it is and (of course) won't be read back indentical as how you thought you wrote it before. Try the .png format instead.
kind regards,
Jos
- 03-06-2010, 03:47 PM #7
Member
- Join Date
- Mar 2010
- Posts
- 6
- Rep Power
- 0
Similar Threads
-
Scanning Image Pixel by Pixel
By the_transltr in forum Advanced JavaReplies: 5Last Post: 08-28-2012, 04:01 PM -
Identify pixel in the image.
By Maiquelnet in forum Java 2DReplies: 2Last Post: 11-12-2009, 07:55 PM -
[SOLVED] manipulating the pixel values of an image and constructinf a new image from
By sruthi_2009 in forum AWT / SwingReplies: 14Last Post: 04-10-2009, 08:46 AM -
how to get rgb value each pixel of an image file
By tOpach in forum New To JavaReplies: 1Last Post: 03-28-2009, 04:38 PM -
How can I get a transparent pixel from an image
By samson in forum Java 2DReplies: 1Last Post: 07-17-2007, 04:10 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks