【发布时间】:2012-08-27 07:05:04
【问题描述】:
我想带一个图像透明度的特殊部分。我怎么能在java中做到这一点?我尝试了一些代码:
public BufferedImage[] splitBackgroundImages() throws IOException {
int count = 0;
bimages = new BufferedImage[chuncks];
for (int x = 0; x < columns; x++) {
for (int y = 0; y < rows; y++) {
// Initialize the image array with image chunks
bimages[count] = image.getSubimage(x * this.chunckwidth, y
* this.chunckheigth, this.chunckwidth,
this.chunckheigth);
Graphics2D gr = bimages[count].createGraphics();
gr.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, 1));
//gr.clearRect(5, 5, chunckwidth-10, chunckheigth -10);
Color transparent = new Color(0,0,0,0);
gr.setPaint(transparent);
gr.setBackground(transparent);
gr.fillRect(5, 5, chunckwidth-10, chunckheigth-10);
/*bimages[count] = gr.getDeviceConfiguration().createCompatibleImage(
chunckwidth, chunckheigth, Transparency.TRANSLUCENT);
*/
gr.fillRect(5, 5, chunckwidth-10, chunckheigth-10);
gr.drawImage(bimages[count++], 0, 0, chunckwidth, chunckheigth,
chunckwidth * y, chunckheigth * x, chunckwidth * y
+ chunckwidth, chunckheigth * x + chunckwidth,
null);
gr.dispose();
}
【问题讨论】:
-
对不起,我完全不知道你要做什么。你将不得不更新你的问题,也许有一些例子??
-
Bring Special Part of an image transparent 的可能重复项。请不要重新发布问题(两次)。可以编辑问题。
-
好的。如何使裁剪图像的区域透明?
标签: java image transparency