簡體   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