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;
任何人都可以給我一個提示嗎?提前致謝!
你在什麼環境中獲取這些圖像? .NET,本機Windows,Linux? .NET有一個內置的圖像庫(System.Image)。其他環境提供了不同的和多種選擇。 – 2012-04-18 05:01:28
@MikeC我在VS2010中實現它。我是新來的C + +不知道我可以在C++中使用什麼替代方案 – Tony 2012-04-18 05:11:31
在Win32 GDI函數中,http://www.christian-etter.de/?p=283 – m4n07 2012-04-18 06:20:32