Java程序无法加载图像文件

时间:2015-06-04 06:28:49

标签: java image for-loop file-upload pixel

我正在尝试运行程序来操纵数字图像的各个像素颜色以产生各种特殊效果,但图片文件未加载。我将图片保存为WashingtonMonument.jpg,每次运行时,都会出现黑屏,表示无法加载。

我的节目是:

import java.awt.*
public class TrueColorsDemo
{
    public static void main(String[] args)
    {
        Picture pictureObj = new Picture("WashingtonMonument.jpg");
        pictureObj.explore();
        int redValue = 0; int greenValue = 0; int blueValue = 0;

        Pixel targetPixel = new Pixel(pictureObj, 0,0);
        Color pixelColor = null;

        for(int y=0; y < pictureObj.getHeight(); y++)
        {
            for(int x = 0; x < pictureObj.getWidth(); x++)
            {
                 targetPixel = pictureObj.getPixel(x,y);
                 pixelColor = targetPixel.getColor();

                 redValue = pixelColor.getRed();
                 greenValue = pixelColor.getGreen();
                 blueValue = pixelColor.getBlue();

                 pixelColor = new Color(redValue, greenValue, blueValue);
                 targetPixel.setColor(pixelColor);
             }
        }

        pictureObj.explore();
        pictureObj.write("NewWashingtonMonument.jpg");
        pictureObj.show();
    }
}

如果有人可以帮我弄清楚如何加载图片以使其在我的程序上工作那将是非常棒的!感谢

0 个答案:

没有答案