[英]Java ImageJ - how to make an image transparent?
我問,我怎樣才能使圖像透明?
實際上,我試圖從IndexColorModel讀取RGB值
ImageProcessor ip1 = img1.getProcessor();
IndexColorModel indexColor = (IndexColorModel)ip1.getColorModel();
然后讀取我需要創建新IndexColorModel的參數
int pixelBits = indexColor .getPixelSize();
int mapSize = cm.getMapSize();
byte[] reds = new byte[mapSize];
cm.getReds(reds);
byte[] greens = new byte[mapSize];
cm.getGreens(greens);
byte[] blues = new byte[mapSize];
cm.getBlues(blues);
並創建新的IndexColorModel並將其設置為另一個具有不同transparentIndex的ImagePlus
indexColor = new IndexColorModel(pixelBits, MapSize, reds, greens, blues, transparentIndex );
ImageProcessor ip3;
ip3.setColorModel(indexColor);
但這是錯誤的想法......
我應該使用帶有cmap和hasAlpha參數的IndexColorModel嗎? 我怎樣才能做到這一點?
提前感謝您的幫助!
我問,我怎樣才能使圖像透明?
要使圖像透明,這太過分了。 對於BufferedImage
類型的輸入image
,我會這樣做:
BufferedImage
tmpImage
,其大小與image
和類型相同: BufferedImage.TYPE_INT_ARGB
tmpImage
Graphics2D
通過向上轉換將其轉換為Graphics2D
。 例如:
BufferedImage tmpImg = new BufferedImage(image.getWidth(), image.getHeight(),
BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = (Graphics2D) tmpImg.getGraphics();
g2d.setComposite(AlphaComposite.SrcOver.derive(0.5f));
// set the transparency level in range 0.0f - 1.0f
g2d.drawImage(image, 0, 0, null);
image = tmpImg;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.