繁体   English   中英

黑色填充与Java中的图像?

[英]Black Padding with images in java?

我有这个问题。 我正在使用此代码旋转图像,但是由于旋转,旋转后的图像在其角处有黑色填充。 我该如何删除?

public static BufferedImage rotate(BufferedImage img, int angle) {
        rotate_checked = false;
        int w = img.getWidth();
        int h = img.getHeight();
        BufferedImage dimg =new BufferedImage(w, h,  BufferedImage.TYPE_BYTE_GRAY);
        Graphics2D g = dimg.createGraphics();
        g.rotate(Math.toRadians(angle), w/2, h/2);
        g.drawImage(img, null, 0, 0);
       return dimg;
} 

您需要创建一个透明图像:

BufferedImage buffer = gc.createCompatibleImage(height,width,Transparency.TRANSLUCENT);

其中“ gc”是Graphics2D对象。 当然,您也可以直接使用新的BufferedImage()创建一个图像,但这将为您的特定图形上下文提供最有效使用的图像。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM