•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Legacy and Other Languages section within the Software Development category of DaniWeb, a massive community of 423,744 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,422 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Legacy and Other Languages advertiser: Programming Forums
Views: 939 | Replies: 1
![]() |
•
•
Join Date: Nov 2007
Posts: 26
Reputation:
Rep Power: 1
Solved Threads: 0
Hi, I have this issue with a J# project I need to complete for uni.
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...
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.
java Syntax (Toggle Plain Text)
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...
java Syntax (Toggle Plain Text)
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; }
edit: I'm using the windows classes System.Drawing.* which is why I haven't posted this on the Java forum.
Last edited by alcoheca : Apr 24th, 2008 at 12:15 pm.
![]() |
•
•
•
•
•
•
•
•
DaniWeb Legacy and Other Languages Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Other Threads in the Legacy and Other Languages Forum
- Previous Thread: Countdown timer
- Next Thread: Matlab Help


Linear Mode