首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在C++中读取图像并将其绘制成加速图像?

如何在C++中读取图像并将其绘制成加速图像?
EN

Stack Overflow用户
提问于 2012-04-18 12:53:19
回答 1查看 119关注 0票数 1

我想从我的计算机中读取图像并将其存储在我的c++程序中。我有一些java图像处理的经验,但完全不知道如何在c++中做到这一点。我想要实现下面的java代码在c++中的作用:

BufferedImage sourceImage = null;

代码语言:javascript
运行
复制
 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;

有人能给我个提示吗?提前感谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-04-18 14:03:36

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10202992

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档