1

我想从我的计算机中读取图像并将其存储在我的 c++ 程序中。我在 java 图像处理方面有一些经验,但完全不知道如何在 c++ 中做到这一点。我想实现下面的java代码在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;

任何人都可以给我一个提示?提前致谢!

4

1 回答 1

0

如果要将图像用作矩阵,可以使用OpenCV库。这个库提供了一个简单的图像加载和存储接口,但它的主要应用是图像处理和计算机视觉。所以它可以是“对鸟的大炮”。

于 2012-04-18T06:03:35.793 回答