i wanna read an image from my computer and store it in my c++ program. i have some experience in java image processing but totally no idea how to do it in c++. i wanna achieve what the java code below does in c++:
BufferedImage sourceImage = null;
try {
// The ClassLoader.getResource() ensures we get the sprite
// from the appropriate place, this helps with deploying the game
// with things like webstart. You could equally do a file look
// up here.
URL url = this.getClass().getClassLoader().getResource(ref);
if (url == null) {
fail("Can't find ref: "+ref);
}
// use ImageIO to read the image in
sourceImage = ImageIO.read(url);
} catch (IOException e) {
fail("Failed to load: "+ref);
}
// create an accelerated image of the right size to store our sprite in
GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
Image image = gc.createCompatibleImage(sourceImage.getWidth(),sourceImage.getHeight(),Transparency.BITMASK);
// draw our source image into the accelerated image
image.getGraphics().drawImage(sourceImage,0,0,null);
// create a sprite, add it the cache then return it
Sprite sprite = new Sprite(image);
sprites.put(ref,sprite);
return sprite;
Anyone can give me a hint? Thanks in advance!
You can use the OpenCV library if you want to work with your image as matrix.
This library provides a simple interface of image loading and storing, but it’s main application is image processing and computer vision. So it can be an “artillery against a bird”.