Java 8 BufferedImage - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 BufferedImage class.

This code example shows how to use the following methods:getHeight, getWidth
      return "capture" + "_" + clickLocation.x + "_" + clickLocation.y + "_" + d.getTime() + ".png";
   } 
    
   public void export(){ 
       
      BufferedImage exportedImage = new BufferedImage(screenImage.getWidth(),screenImage.getHeight(),BufferedImage.TYPE_INT_RGB);
      Graphics2D g = (Graphics2D) exportedImage.getGraphics();
      g.drawImage(screenImage,0,0,null);
       
      // draw cursor 
      int cursorSize = 10;
      Color cursorColor = Color.red;
      Ellipse2D.Double circle = new Ellipse2D.Double((double)clickLocation.x-cursorSize/2,(double)clickLocation.y-cursorSize/2,cursorSize,cursorSize);
      g.setColor(cursorColor);
      g.draw(circle);
 
      try { 
         ImageIO.write(exportedImage, "png", new File("/Users/tomyeh/Desktop/captured" + encodeFilename()));
      } catch (IOException e) {
         e.printStackTrace();
9
CodeRank
This code example shows how to use the following methods:getHeight, getWidth
 
	@Override 
	public Dimension getPreferredSize () {
		Dimension dimension = super.getPreferredSize();
		if(image != null){
			dimension.width = image.getWidth();
			dimension.height = image.getHeight();
		} 
		return dimension;
	} 
} 
9
CodeRank
This code example shows how to use the following methods:getHeight, getWidth
		return filter(src, (BufferedImage)null);
	} 
	 
	public BufferedImage filter( BufferedImage src, BufferedImage dst ) {
         
		int width = src.getWidth();
	    int height = src.getHeight();
 
	    if(xrt==0)xrt=width;
	    if(xrb==0)xrb=width;
	    if(yrb==0)yrb=height;
	    if(ylb==0)ylb=height;
	     
	    if(xlt<0) xlt=width+xlt;
	    if(xrt<0) xrt=width+xrt;
	    if(xrb<0) xrb=width+xrb;
	    if(xlb<0) xlb=width+xlb;
	     
	    if(ylt<0) ylt=width+ylt;
	    if(yrt<0) yrt=width+yrt;

9
CodeRank
This code example shows how to use the following methods:getHeight, getWidth
	       		"</html>\n"; 
	} 
	 
    private Dimension calculateResizeSize(BufferedImage image) {
        Dimension result;
        if (image.getWidth() > image.getHeight()) {
            result = new Dimension(MAX_COVER_IMAGE_SIZE, (int) (((double) MAX_COVER_IMAGE_SIZE / (double) image.getWidth()) * (double) image.getHeight()));
        } else { 
            result = new Dimension((int) (((double) MAX_COVER_IMAGE_SIZE / (double) image.getHeight()) * (double) image.getWidth()), MAX_COVER_IMAGE_SIZE);
        } 
        return result;
    } 
 
 
    @SuppressWarnings("unused") 
	private byte[] createThumbnail(byte[] imageData) throws IOException {
        BufferedImage originalImage = ImageIO.read(new ByteArrayInputStream(imageData));
        Dimension thumbDimension = calculateResizeSize(originalImage);
        BufferedImage thumbnailImage = createResizedCopy(originalImage, (int) thumbDimension.getWidth(), (int) thumbDimension.getHeight(), false);
        ByteArrayOutputStream result = new ByteArrayOutputStream();

8
CodeRank
This code example shows how to use the following methods:getHeight, getWidth
   public void testCapture(){ 
      ScreenImage img = scr.capture();
      assertNotNull(img); 
      BufferedImage bimg = img.getImage();
      Rectangle bounds = scr.getBounds();
      assertEquals(bimg.getWidth(), bounds.getWidth());
      assertEquals(bimg.getHeight(), bounds.getHeight());
   } 
 
   @Test
   public void testBounds(){ 
      Rectangle bound = scr.getBounds();
      assertNotNull(bound);
   } 
    
 
   @Test
   public void testLockScreen(){ 
      MonkeyDevice dev = (MonkeyDevice)scr.getRobot().getDevice(); // still can use MonkeyDevice if needed.
      if(scr.exists("lock.png", 3) == null)
9
CodeRank
This code example shows how to use the following methods:getHeight, getWidth
        // position, and scale it according to the given width and height. 
        Transform imageTrans = new Transform();
        // Move to the image position. Convert x, y, which are centered coordinates, 
        // to "real" coordinates.  
        double factor = getScaleFactor();
        double finalWidth = image.getWidth() * factor;
        double finalHeight = image.getHeight() * factor;
        imageTrans.translate(x - finalWidth / 2, y - finalHeight / 2);
        // Scaling only applies to image that have their desired width and/or height set. 
        // However, getScaleFactor return 1 if height/width are not set, in effect negating 
        // the effect of the scale. 
        imageTrans.scale(getScaleFactor());
        double a = clamp(alpha);
        Composite composite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float) a);
        Composite oldComposite = g.getComposite();
        g.setComposite(composite);
        g.drawRenderedImage(image, imageTrans.getAffineTransform());
        g.setComposite(oldComposite);
        restoreTransform(g);
    } 

9
CodeRank
This code example shows how to use the following methods:getColorModel, getHeight, getRaster, getWidth
		return height;
	} 
 
    public BufferedImage filter( BufferedImage src, BufferedImage dst ) {
         
    	int w = src.getWidth();
        int h = src.getHeight();
 
        if(x<0)x=0;
        if(y<0)y=0;
        if(x>w)x=w;
        if(y>h)y=h;
         
         
		dst=ImageUtil.createBufferedImage(src,width,height);
		 
 
         
 
		Graphics2D g = dst.createGraphics();

8
CodeRank
This code example shows how to use the following methods:getHeight, getWidth
      setScale(1.0f);       
   } 
    
   public void setScale(float scale){
      this.scale = scale;
      w = (int) (scale*image.getWidth());
      h = (int) (scale*image.getHeight());
      setActualSize(new Dimension(w,h));
   } 
       
   public void paintComponent(Graphics g){
      Graphics2D g2d = (Graphics2D) g;
       
      g2d.drawImage(image, 0, 0, getActualWidth(), getActualHeight(), null); 
      g2d.drawRect(0,0,getActualWidth()-1,getActualHeight()-1);
   } 
 
   public void setImage(BufferedImage image) {
      this.image = image;
   } 
9
CodeRank
This code example shows how to use the following methods:getColorModel, getHeight, getRaster, getWidth

8
CodeRank
This code example shows how to use the following methods:getHeight, getWidth
	public float getRadius() { 
		return radius;
	} 
 
    public BufferedImage filter( BufferedImage src, BufferedImage dst ) {
		icentreX = src.getWidth() * centreX;
		icentreY = src.getHeight() * centreY;
		if ( radius == 0 )
			radius = Math.min(icentreX, icentreY);
		radius2 = radius*radius;
		return super.filter( src, dst );
	} 
	 
	protected void transformInverse(int x, int y, float[] out) {
		float dx = x-icentreX;
		float dy = y-icentreY;
		float distance = dx*dx + dy*dy;
		if (distance > radius2) {
			out[0] = x;
			out[1] = y;
9
CodeRank
See Code Examples for Java 8 BufferedImage Methods: