Skip to main content

Posts

Showing posts from April, 2013

Writing One Dimensional Array as Image ( Java )

Welcome back ,I'm still writing the application from the last post, I founded that I must redraw the image to show the result , I faced Many problems while writing the Method write Image first the image was totally black which is not correct , I searched the web for a solution especially stack overflow site , I'm gonna tell you what I gain , I hope the post help you in shaa Allah . public void write_image(int[] image_1d, int width, int height) throws IOException {            WritableRaster raster= Raster.createWritableRaster         (new PixelInterleavedSampleModel(0, width,height, 1,          1920,new int[] {0}), new Point(0,0));         int k =0 ;         for(int i = 0 ; i < width ; i++ )          {          for(int j = 0 ; j < height ; j++)          {              raster.setSample(i,j,0,image_1d[k]);              k++;          }          }         BufferedImage image =new BufferedImage(width,height,                                  BufferedImage.

Reading Image in 1 Dimensional Array

Hello , I'm writing an application and I need to write a method which can read an Image, I found it hard complicated in some times, I wrote a One and I'd like to share it with you note it is written with Java and it convert gray-scale images to binary 0-1 .  public int [] read_image_in_1d () throws IOException{         // array to be returned          int image_1d []= null ;         // File object to hold the destination          File f = new File("test.jpg");         // buffer for the Image          BufferedImage  image = ImageIO.read(f);         // raster to the image         Raster raster = image.getData();         // width          int width = raster.getWidth();         // height          int height = raster.getHeight();         // initialization for the Array          image_1d = new int[width * height];         int k = 0;         //get the image in the array         for(int i = 0 ; i < width ; i++)             for(int j = 0 ; j < height