Hi, I have this issue with a J# project I need to complete for uni.
public class Sprite
{
private Image m_image;
public Sprite(Image image)
{
m_image = image;
}
public int getWidth()
{
return m_image.get_Width();
}
public int getHeight()
{
return m_image.get_Height();
}
public void draw(Graphics g, int x, int y)
{
g.DrawImage(this.m_image, x, y);
}
}
This compiles fine, however when I run the program the Image member variable m_image ends up with a Bitmap type rather than an Image.
Here's is the code where the bitmap is loaded, at no point do I cast, or use the bitmap type, so I'm left unsure how to fix it...
public Sprite getSprite(String ref)
{
/* check for cached sprite */
if (imageCache.get(ref) != null)
{
return (Sprite)imageCache.get(ref);
}
/* not found, load in bitmap now */
Image inputFile = null;
try
{
inputFile = Image.FromFile(ref + ".bmp");
}
catch (Exception e)
{
System.err.println("Load failed: " + ref + ".bmp");
System.exit(0);
}
// create a sprite, add it the cache then return it
Sprite sprite = new Sprite(inputFile);
imageCache.put(ref, sprite);
return sprite;
}
This cause an exception of "invalid paramater".
edit: I'm using the windows classes System.Drawing.* which is why I haven't posted this on the Java forum.