2012-04-18 18 views
1

私のコンピュータから画像を読んで、それを私のC++プログラムに保存したいと思います。私はJavaの画像処理でいくつかの経験があるが、C++でそれを行う方法は全く考えられていない。私は以下のjavaコードがC++で何を達成したいのですか?イメージを読み込んで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; 

誰でも私にヒントを与えることができますか?前もって感謝します!

+0

どのような環境でこれらの画像を取得していますか? .NET、ネイティブWindows、Linux? .NETには画像ライブラリ(System.Image)が組み込まれています。他の環境では、さまざまな代替手段がいくつか用意されています。 –

+0

@MikeC VS2010で実装します。私はC++を初めて使っていて、C++で何ができるのかわからない – Tony

+0

Win32 GDI関数では、http://www.christian-etter.de/?p=283 – m4n07

答えて

0

イメージをマトリックスとして使用する場合は、OpenCVライブラリを使用できます。 このライブラリは画像の読み込みと保存の簡単なインタフェースを提供しますが、主な用途は画像処理とコンピュータビジョンです。それは "鳥に対して砲撃"することができます。

関連する問題