显示.png文件的方法 [英] ways of displaying a .png-file

查看:95
本文介绍了显示.png文件的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!



我有以下问题:



我有一些.png文件,我希望在给定Rect中的CWnd中显示。



我找到了一些代码,它将一个.png文件的BGRA值读入一个数组,然后从这个数组中创建一个CBitmap,然后显示CBitmap。



这样做有什么不利吗?有更好的方法吗?



某处有ShowPng功能吗?:-)



感谢您的帮助!

Hi all!

I have the following question:

I have some .png files, which i want to Display in a CWnd in a given Rect.

I found some code, which reads the BGRA values of one .png-File into an array and then creates a CBitmap out of this array and then displays the CBitmap.

Is there any disadvantage of doing this? Is there a better way of doing it?

Is there a ShowPng function somewhere?:-)

thanks for your help!

推荐答案

尝试检查以下CodeProject文章的代码(特别是第一篇非常受欢迎)。比较和对比。



CxImage [ ^ ]



支持PNG的用户绘制按钮对于Visual C ++ 6.0和VS2005,具有透明度的文件 [ ^ ]



正在加载JPG& PNG资源使用GDI + [ ^ ]
Try examining the code on the following CodeProject articles (the first one in particular is very popular). Compare and contrast.

CxImage[^]

A user draw button that supports PNG files with transparency, for Visual C++ 6.0 and VS2005[^]

Loading JPG & PNG resources using GDI+[^]


不,纯C ++和MFC中没有这样的功能。你在做什么是绝对正确的。首先将PNG转换为内存表示,然后从中形成位图。即使MFC中有库函数,它也必须以相同的方式执行。



如果你经常使用该图像,你应该考虑缓存内存表示,这样你就不必多次从磁盘读取文件了。
No, there is no such function in pure C++ and MFC. What you are doing is absolutely correct. First convert the PNG into a memory representation and then form a bitmap out of it. Even if there was a library function in MFC, it had to do it in the same way.

If you are using that image often, you should think about caching the memory representation so that you don't have to read the file from disk multiple times.


使用 GDI + 很简单,见< a href =https://msdn.microsoft.com/en-us/library/windows/desktop/ms533830(v=vs.85).aspx>加载和显示位图 [ ^ ]在 MSDN

这与 GdiplusStartup / GdiplusShutdown 一起使用(此处的示例用法:< a href =https://msdn.microsoft.com/en-us/library/ms533895(v=vs.85).aspx>画一条线 [ ^ ] MSDN您只需要)。
With GDI+ is simple matter, see "Loading and Displaying Bitmaps"[^] at MSDN.
That's together with GdiplusStartup/GdiplusShutdown (sample usage here: "Drawing a Line"[^] at MSDN) is all you need.


这篇关于显示.png文件的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆