Search
Sponsors
Sponsors

Archive for the ‘Multimedia’ Category

Screen capture example

Thursday, August 25th, 2011

 

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.ImageIO;

class ScreenCapture {
  public static void main(String args[]) throws AWTException, IOException {
     // Captures the image from the screen
     BufferedImage screencapture = new Robot().createScreenCapture(
           new Rectangle(Toolkit.getDefaultToolkit().getScreenSize())); //Gets the size of the screen

     // Writes the File as a PNG
     File file = new File("screencapture.png");//Saves your file in the project folder
     ImageIO.write(screencapture, "png", file);
  }
}

Set Image Color as Transparent

Thursday, August 25th, 2011

 

public Image makeColorTrans(Image im,final Color c)
    {
        ImageFilter filter = new RGBImageFilter()
        {
      // the color we are looking for… Alpha bits are set to opaque
      public int markerRGB = c.getRGB() | 0xFF000000;

      public final int filterRGB(int x, int y, int rgb) {
        if ( ( rgb | 0xFF000000 ) == markerRGB ) {
          // Mark the alpha bits as zero - transparent
          return 0×00FFFFFF & rgb;
          }
        else {
          // nothing to do
          return rgb;
          }
        }
      };

    ImageProducer ip = new FilteredImageSource(im.getSource(), filter);
    return Toolkit.getDefaultToolkit().createImage(ip);
    }

Translate