import java.awt.*; import java.awt.image.*; public class Tah03 extends Canvas{ int vx, vy, ux, uy, laius, korgus; Image pilt; Graphics piltg; Tah03(int w, int h){ resize(w, h); laius=w; korgus=h; setBackground(Color.white); } public boolean mouseDown(Event e, int x, int y){ ux=x; uy=y; return true; } /* public void anna(TextArea area){ GetPixels(pilt, 0, 0, 5, 5, area); } */ public boolean mouseDrag(Event e, int x, int y){ vx=ux; vy=uy; ux=x; uy=y; repaint(); return super.mouseDown(e, x, y); } public void update(Graphics g){ piltg.drawLine(vx, vy, ux, uy); // g.clipRect(Math.min(vx, ux)-1, Math.min(vy, uy)-1, Math.abs(vx-ux)+100, Math.abs(vy-uy)+100); // g.clipRect(0, 0, 50, 30); paint(g); } public void paint(Graphics g){ if (pilt==null){ pilt=createImage(size().width, size().height); piltg=pilt.getGraphics(); piltg.setColor(Color.black); } g.drawImage(pilt, 0, 0, null); } /* public void handleSinglePixel(int x, int y, int pixel, TextArea area) { int alpha = (pixel >> 24) & 0xff; int red = (pixel >> 16) & 0xff; int green = (pixel >> 8) & 0xff; int blue = (pixel ) & 0xff; area.appendText(red+"\n"); // Deal with the pixel as necessary... }*/ public String pildistring() { int[] pixels = new int[laius*korgus]; char c[] = new char[laius*korgus]; int ik=0; String s=""; PixelGrabber pg = new PixelGrabber(pilt, 0, 0, laius, korgus, pixels, 0, laius); try { pg.grabPixels(); } catch (InterruptedException e) { System.err.println("interrupted waiting for pixels!"); return "x"; } if ((pg.status() & ImageObserver.ABORT) != 0) { System.err.println("image fetch aborted or errored"); return "x"; } for (int j = 0; j < korgus; j++) { for (int i = 0; i < laius; i++) { // look at the pixel // int red = (pixel >> 16) & 0xff; if (((pixels[j * laius + i] >> 16) & 0xff)==0){c[ik++]='m';} else if (((pixels[j * laius + i] >> 16) & 0xff)==255){c[ik++]='v';} else {c[ik++]='k';} } } s=new String(c); return s; } public void stringipilt(String s){ Image abi; int[] pixels = new int[laius*korgus]; char c[]=new char[laius*korgus]; int i, p; c=s.toCharArray(); p=s.length(); for(i=0; i