【发布时间】:2015-04-06 22:39:51
【问题描述】:
-
Pre:接收缓冲图像和要删除的像素数
- Post:创建并返回接收到的图像的副本,其中删除了给定数量的图像剩余像素
我在使用此方法时遇到问题,因为我需要删除随机像素...我只制作了要打印的图像的新副本,但我需要更改它以便删除给定的像素数... .谁能帮忙?
public static BufferedImage removePixels(BufferedImage img,int numToRemove)
{
//so far what I have gotten
BufferedImage copy = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_ARGB);
copy.getGraphics().drawImage(img, 0,0,null);
return copy;
}
【问题讨论】:
-
我忘记了...实际上只是通过将像素设置为透明来删除它们...
-
我会首先使用
Math.random()来查找随机像素坐标并将它们设置为透明。也许使用 for 循环来控制这种情况发生的次数,使用 ArrayList 来跟踪已删除的像素?
标签: java bufferedimage pixels