0

I have Image_1.jpg.I got Image Pixel Value in 2D Array from Image_1.jpg.I have set First 8*8 blocks Value of 2D Array as following.

16 , 16 , 16 , 16 , 16 , 16 , 16 , 16 , 
16 , 16 , 16 , 16 , 16 , 16 , 16 , 16 , 
16 , 16 , 16 , 16 , 16 , 16 , 16 , 16 , 
16 , 16 , 16 , 16 , 16 , 16 , 16 , 16 , 
16 , 16 , 16 , 16 , 16 , 16 , 16 , 16 , 
16 , 16 , 16 , 16 , 16 , 16 , 16 , 16 , 
16 , 16 , 16 , 16 , 16 , 16 , 16 , 16 , 
16 , 16 , 16 , 16 , 16 , 16 , 16 , 16 , 

and construct image as Img.jpg. Again take This Img.jpg Image Read this in 2D Array.and Read First 8*8 blocks.I got following Values.

-16776690 , -16776690 , -16776432 , -16776176 , -16775922 , -16775927 , -16776190 , -16645120 , 
-16776944 , -16776688 , -16776432 , -16776176 , -16775922 , -16775925 , -16776188 , -16645376 , 
-16777198 , -16776940 , -16776940 , -16776684 , -16776430 , -16776434 , -16776697 , -16580096 , 
-16777196 , -16777196 , -16776939 , -16776683 , -16776428 , -16776432 , -16776695 , -16580350 , 
-16646124 , -16711660 , -16777195 , -16776937 , -16776683 , -16776686 , -16711413 , -16449532 , 
-16646126 , -16711662 , -16776940 , -16776940 , -16776940 , -16776944 , -16711413 , -16449532 , 
-16449523 , -16580594 , -16711664 , -16776944 , -16776944 , -16776947 , -16645881 , -16384000 , 
-16449529 , -16449527 , -16646133 , -16776693 , -16776695 , -16776442 , -16645632 , -16383744 ,

I want those values as 16.I wrote following code for this.what should I do?

 /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package testing;

    import java.awt.image.BufferedImage;
    import java.io.File;
    import javax.imageio.ImageIO;

    /**
     *
     * @author pratibha
     */
    public class ConstructImage{
        int[][] PixelArray;
        public ConstructImage(){
            try{

            BufferedImage bufferimage=ImageIO.read(new File("C:\\photo\\Modified\\image_1.jpg"));
            int height=bufferimage.getHeight();
            int width=bufferimage.getWidth();
            PixelArray=new int[width][height];
            for(int i=0;i<width;i++){
                for(int j=0;j<height;j++){
                    PixelArray[i][j]=bufferimage.getRGB(i, j);
                }
            }
            ///////create Image from this PixelArray

             for(int i=0;i<8;i++){
                for(int j=0;j<8;j++){
                    PixelArray[i][j]=16;
                }
            }
             for(int i=0;i<8;i++){
                for(int j=0;j<8;j++){
                  System.out.print(PixelArray[i][j]+" , ");
                }
                System.out.println("");
            }






            BufferedImage bufferImage2=new BufferedImage(width, height,BufferedImage.TYPE_INT_RGB);
              for(int x=0;x<width;x++){
                    for(int y=0;y<height;y++){
              bufferImage2.setRGB(x, y, PixelArray[x][y]);

                }
             }

             File outputfile = new File("C:\\photo\\Modified\\img.jpg");
             ImageIO.write(bufferImage2, "jpg", outputfile);
            ///////////////////////////////////////////////////////////////////
                  BufferedImage bufferimage1=ImageIO.read(new File("C:\\photo\\Modified\\img.jpg"));
            int height1=0;
            height1=bufferimage1.getHeight();
            int width1=0;
            width1=bufferimage1.getWidth();
            int[][] PixelArray1=new int[width1][height1];
            for(int i=0;i<width1;i++){
                for(int j=0;j<height1;j++){
                    PixelArray1[i][j]=bufferimage1.getRGB(i, j);
                }
            }
            ///////create Image from this PixelArray

             for(int i=0;i<8;i++){
                for(int j=0;j<8;j++){ 
                    System.out.print(PixelArray1[i][j]+" , ");
                }
                System.out.println();
            }
            System.out.println(Integer.toBinaryString(222));
            System.out.println(Integer.signum(93226268));;
            }
            catch(Exception ee){
                ee.printStackTrace();
            }
        }

        public static void main(String args[]){
            ConstructImage c=new ConstructImage();
        }
    }
2
  • You question is unclear. Do you want to copy the image? Do you want to extract a sub-image? Do you want to convert the image? Do you want to print it to the console? Commented Aug 13, 2012 at 11:43
  • Actually I want to set values first 8*8 block of Image for Stregnography purpose Commented Aug 13, 2012 at 11:44

1 Answer 1

1

I'm not sure that you want to be setting the Image values directly with an int... I guess what you really want to do is to set it to "grayscale value 16". What you're actually doing is setting the pixels to "red 0, green 0, blue 16".

First, try creating a Color(16,16,16) and then call getRGB() on it.

BTW, JPG is a lossy compression, so you can't expect the values to exactly match when you save/load - you might want to use PNG instead.

Incidentally, unless you're trying to meet the API requirements of a third party library, I would recommend staying with accessing the BufferedImage class directly instead of trying to create an array copy. Uncompressed images can get really big really quickly and you'll run out of memory by needlessly doubling your memory usage.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.