导入jpg图像时遇到问题(Java)

时间:2017-02-02 04:54:35

标签: java eclipse 2d

您好我从其他课程导入图片时遇到问题。

  

错误指出“'ImageLoader'无法解析”

并且文件名正确。我正在使用的构造函数是公开的,我不知道还有什么可以改变。

这是导致ACCOUNT_NUMBER,CUSTOMER_NAMES,VALUE_DATE,BOOKING_DATE,TRANSACTION,ACCOUNT_TYPE,BALANCE_TYPE,REFERENCE,MONEY.OUT,MONEY.IN,RUNNING.BALANCE,BRANCH,EMAIL,ACTUAL.BALANCE,AVAILABLE.BALANCE 1000000001,TEST,,2847899,KES,Account,,,10/10/2016,9/11/2016,15181800,UPPER HILL BRANCH,another@yahoo.com,5403.75,5403.75, 1000000001,,9/11/2016,9/11/2016,Opening Balance,,,,,,4643.22,,,,, 1000000001,,12/10/2016,12/10/2016,Mobile Mpesa Transfer,,,,1533,,3110.22,,,,, 1000000001,,17-10-2016,17-10-2016,ATM Withdrawal,,,6.29006E+11,1000,,2110.22,,,,, 1000000001,,17-10-2016,17-10-2016,ATM Withdrawal,,,6.29118E+11,2000,,110.22,,,,, 1000000001,,17-10-2016,17-10-2016,Mobile Mpesa Transfer,,,,2083,,-1972.78,,,,, 1000000001,,17-10-2016,17-10-2016,Transfer from Mpesa,,,,0,4000,2027.22,,,,, 1000000001,,18-10-2016,18-10-2016,Mobile Mpesa Transfer,,,,333,,1694.22,,,,, 文件(更具体地说是"Game.java")错误的行:

"ImageLoader"

这是我的testImage = ImageLoader.LoadImage("/textures/Hello.jpg"); 文件,该行正在抓取:

"ImageLoader.java"

3 个答案:

答案 0 :(得分:1)

您的方法名称中有拼写错误

 public static BufferedImage laodImage(String path)

应更改为:

 public static BufferedImage loadImage(String path)

同时将您的方法调用更改为:

testImage = ImageLoader.loadImage("/textures/Hello.jpg");

方法名称应以java中的小写字母开头。

答案 1 :(得分:0)

确保ImageLoader与加载图像的类位于同一文件夹中或导入Graphix包

import Graphix.ImageLoader;

答案 2 :(得分:0)

尝试以下代码...

示例代码

import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class LoadImageDemo{
    BufferedImage image = null;
    int width;
    int height;
    public LoadImageDemo() {
        File inputImg = new File("\\textures\\Hello.jpg");
        try {
            image = ImageIO.read(inputImg);
        } catch (IOException e) {
            e.printStackTrace();
        }
        width = image.getWidth();
        height = image.getHeight();
        int count = 0;
        for(int i=0; i<height; i++){
            for(int j=0; j<width; j++){
               count++;
               Color c = new Color(image.getRGB(j, i));
               System.out.println("S.No: " + count + " Red: " + c.getRed() +"  Green: " + c.getGreen() + " Blue: " + c.getBlue());
            }
         }
    }
    public static void main(String[] args) {
        new LoadImageDemo();
    }

}

执行上面的示例时,它会打印图像的像素

如果您想绘制图像,可以点击此链接。 Drawing Image Click me