需要帮助获取图像的高度(可能的继承问题) [英] Need help getting height of image (Possible Inheritance Problem)
本文介绍了需要帮助获取图像的高度(可能的继承问题)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
好的,这是KernelHandler类
Ok so this is the KernelHandler Class
public class KernelHandler extends ImageHandler
我得到一个无法找到方法getWidth()
I'm getting a cannot find method getWidth()
我知道它与继承有关,但我需要帮助
I know it has something to do with inheritance, but I need help, please
//造船厂
public KernelHandler(String nameOfFile)
{
super(nameOfFile);
}
// here's the super constructor
public ImageHandler(String nameOfFile){
URL imageURL = getClass().getClassLoader().getResource(nameOfFile);
try
{
myImage = ImageIO.read(imageURL);
}
catch ( IOException e )
{
System.out.println( "image missing" );
}
//这里是试图使用
public static int numOfRedBoxes(String nameOfImg)
{
KernelHandler myHand = new KernelHandler(nameOfImg);
for(int i = 0; i < myHand.getWidth(); i++)
for(int j = 0; j < myHand.getHeight(); j++){
if(img.getRGB(i, j) == red){
numOfRedBoxes++;
}
}
}
return numOfRedBoxes;
}
推荐答案
尝试更改myHand对于超类,它将是这样的:
Try changing the type of myHand to that of the super class , it would be something like:
ImageHandler myHand = new KernelHandler(nameOfImg);
这篇关于需要帮助获取图像的高度(可能的继承问题)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文