Joined: Tue Mar 27, 2007 10:55 pm Posts: 2277 Location: Earth Has thanked: 39 time Have thanks: 61 time
* Project Name:
Screen Capture and multicast * Programmer:Sunil Kumar Gupta * Type:Java Swing * Technology:Java * IDE:Any * Description:This project captures the screen and compress the captured image and then multicast it, so that all the machines connected with that multicast address can receive the captured screen.
public class ImageCanvas implements Runnable { public Robot robo; byte [] dataone; int count=0; public BufferedImage myImage; public InetAddress multicastAddress; public MulticastSocket socket; public static void main(String args[]) { try { ImageCanvas img=new ImageCanvas(); new Thread(img).start(); } catch(Exception e) { System.out.println("Errr in Imgcanvas "+e); } } public void start() { } public ImageCanvas() { try { robo=new Robot(); } catch(Exception e) { System.out.println("Errr in Imgcanvas cons "+e); } } public void run() { for (;;) { try { myImage=robo.createScreenCapture(new Rectangle(0,0,800,800)); //myImage=robo.createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize())); int x1=155;int y1=150;int x2=205;int y2=185; int red = 255; int green = 0; int blue = 0; int transparency = 100; // do the highlighting Graphics graphics = myImage.getGraphics(); Color color = new Color(red, green, blue,255 * transparency/100); graphics.setColor(color); graphics.drawString("Screen Capture " + new java.util.Date(),50, myImage.getHeight() - 10); int thumbWidth=500,thumbHeight=500; double thumbRatio = (double)thumbWidth / (double)thumbHeight; int imageWidth = myImage.getWidth(null); int imageHeight = myImage.getHeight(null); double imageRatio = (double)imageWidth / (double)imageHeight; if (thumbRatio < imageRatio) { thumbHeight = (int)(thumbWidth / imageRatio); } else { thumbWidth = (int)(thumbHeight * imageRatio); } // draw original image to thumbnail image object and // scale it to the new size on-the-fly
BufferedImage thumbImage = new BufferedImage(thumbWidth,thumbHeight, BufferedImage.TYPE_INT_RGB); Graphics2D graphics2D = thumbImage.createGraphics();
image=image.getScaledInstance(this.getWidth(),this.getHeight(),2); tracker = new MediaTracker(this); tracker.addImage(image,0); } catch(Exception e) System.out.println("Errr in test "+e); } try { tracker.waitForID(0); } catch(Exception e) { System.out.println("Errr in tracker "+e); } repaint(); } // end of for loop } public void paint (Graphics g) { try { g.drawImage(image,0,0,this); } catch(Exception e){System.out.println("Errr in paint "+e);} return; } public void update(Graphics g) { paint(g); }
}
public class Test { public static void main(String args[]) { JFrame fram = new JFrame(); screenCapture capture = new screenCapture(); fram.getContentPane().add(capture); fram.setSize(510,520); fram.setLocation(600,200); fram.show(); new Thread(capture).start(); } } //end of Test.java