import java.lang.*; import java.awt.*; import java.net.*; import java.io.*; import java.util.*; import java.awt.image.*; public class Grafika { public Image imageobj; public int imageHeight; public int imageWidth; public Grafika(Image image) { imageobj = image; imageWidth = image.getWidth(null); imageHeight = image.getHeight(null); } public int[][] getRedArray() { int values[] = new int[imageWidth * imageHeight]; PixelGrabber grabber = new PixelGrabber(imageobj.getSource(), 0, 0, imageWidth, imageHeight, values, 0, imageWidth); try { if(grabber.grabPixels() != true) { try { throw new AWTException("Grabber returned false: " + grabber.status()); } catch (Exception e) {}; } } catch (InterruptedException e) {}; int r[][] = new int[imageWidth][imageHeight]; int index = 0; for (int y = 0; y < imageHeight; ++y){ for (int x = 0; x < imageWidth; ++x) { r[x][y] = ((values[index] & 0x00ff0000) >> 16); index++; } } return r; } public int[][] getGreenArray() { int values[] = new int[imageWidth * imageHeight]; PixelGrabber grabber = new PixelGrabber(imageobj.getSource(), 0, 0, imageWidth, imageHeight, values, 0, imageWidth); try{ if(grabber.grabPixels() != true) { try { throw new AWTException("Grabber returned false: " + grabber.status()); } catch (Exception e) {}; } } catch (InterruptedException e) {}; int g[][] = new int[imageWidth][imageHeight]; int index = 0; for (int y = 0; y < imageHeight; y++) { for (int x = 0; x < imageWidth; x++) { g[x][y] = ((values[index] & 0x0000ff00) >> 8); index++; } } return g; } public int[][] getBlueArray() { int values[] = new int[imageWidth * imageHeight]; PixelGrabber grabber = new PixelGrabber(imageobj.getSource(), 0, 0, imageWidth, imageHeight, values, 0, imageWidth); try { if(grabber.grabPixels() != true) { try { throw new AWTException("Grabber returned false: " + grabber.status()); } catch (Exception e) {}; } } catch (InterruptedException e) {}; int b[][] = new int[imageWidth][imageHeight]; int index = 0; for (int y = 0; y < imageHeight; ++y) { for (int x = 0; x < imageWidth; ++x) { b[x][y] = (values[index] & 0x000000ff); ++index; } } return b; } public int[] convertRGBtoArray(int[][] R, int[][] G, int[][] B) { int x = 0; int y = 0; int index = 0; int array[] = new int[imageWidth * imageHeight]; for (y=0; y16777216) array[index]=16777216; if(array[index]<-16777216) System.out.println("majhno:"+array[index]); index++; } } return array; } public byte[] convertGrayToArray1(int[][] R) { byte array[] = new byte[imageWidth * imageHeight]; int x = 0; int y = 0; int index = 0; int G[][] = new int[imageWidth][imageHeight]; int B[][] = new int[imageWidth][imageHeight]; G = R; B = R; for (y=0; y