Png图片动态创建. [英] Png image Dynamic creation.

查看:218
本文介绍了Png图片动态创建.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我正在开发C ++应用程序,我必须将结果显示为图像.因此,我必须动态绘制png图像,并将其他组件(例如图像)放入其中.
我正在寻找使用GDI +的解决方案,但我不太清楚如何进行操作.
谁能告诉我该怎么做?
在此先感谢您的宝贵帮助.
最好的问候.

Hello everyone, I''m developping a C++ application and I must display the result as an image. So that, I must draw dynamicly a png image and put into it other components like images.
I''m searching for a solution with GDI+ but I''m not understanding very well how to proceed.
Can anyone tell me how to do ?
Many thanks in advance for your precious help.
Best regards.

推荐答案

亲爱的穆拉德先生,

好吧,您在这里不是很具体.您是否正在使用CLI(托管)代码?如果您使用的是托管框架,请创建对System::Drawing::Graphics对象的引用(使用Control.CreateGraphics()方法),并使用Graphics.DrawImage(Image image, Point point)或许多重载之一.
如果您使用的是本机C ++,请使用Graphics::Graphics对象>构造函数,然后调用DrawImage方法.

如果您需要更多帮助,请澄清您的问题或添加一个最少的示例,我们将为您提供更多帮助.
Dear Mr. Mourad,

Well, you''re not very specific here. Are you using CLI (managed) code? If you''re using the managed framework, create a reference to a System::Drawing::Graphics object (use the Control.CreateGraphics() method), and use Graphics.DrawImage(Image image, Point point) or one of the many overloads.
If you''re using native C++, create a Graphics::Graphics object using one of the Constructors, then call the DrawImage method.

If you need more help, clarify your question a bit or add a minimum example, and I''ll help more.


亲爱的先生,

我坚持我的原始回答,使用Graphics::Graphics类和gdiplus.h文件中的draw方法(DrawStringDrawImage等).让我知道您是否有问题...请参阅 [
Dear Sir,

I stand by my original response, use the Graphics::Graphics class, and the draw methods (DrawString, DrawImage, et cetera) in the gdiplus.h file. Let me know if you have problems...see this[^] page, too. Get past all the crap about the library version stuff and how they''re exported. Read starting one paragraph before
A Basic GDI+ Application
Good luck.
Aaron
ProCure


感谢您对我的问题的理解.
我更改了工作方法,并使用了此功能
Thanks for your intrest to my problem.
I''ve changed the work method and I''ve used this function
void CWWizard::CreateBMPFile(HWND hwnd, LPTSTR pszFile, std::vector<CString> bmpListBmp, HDC hDC) //PBITMAPINFO pbi, HBITMAP hBMP
 { 
    HANDLE hf;                 // file handle  
    BITMAPFILEHEADER hdr;       // bitmap file-header  
    PBITMAPINFOHEADER pbih;     // bitmap info-header  
    LPBYTE lpBits;              // memory pointer  
    DWORD dwTotal;              // total count of bytes  
    DWORD cb;                   // incremental count of bytes  
    BYTE *hp;                   // byte pointer  
    DWORD dwTmp; 

	if((int)bmpListBmp.size() > 0)
	{
		// si liste contient des elements --> Create the .PNG file.  
		hf = CreateFile(pszFile, 
                   GENERIC_READ | GENERIC_WRITE, 
                   (DWORD) 0, 
                    NULL, 
                   CREATE_ALWAYS, 
                   FILE_ATTRIBUTE_NORMAL, 
                   (HANDLE) NULL); 

		if (hf == INVALID_HANDLE_VALUE) 
			errhandler("CreateFile", hwnd); 

		hdr.bfType = 0x4d42;        // 0x42 = "B" 0x4d = "M"  

		for(int nIdImg = 0; nIdImg < (int)bmpListBmp.size(); nIdImg++)
		{
			//recuperer le hBITMAP et le hederindo de chq image
			HBITMAP hBMP = GetBmpUnifie(bmpListBmp[nIdImg], m_BrosseFondWizard);
			PBITMAPINFO pbi = CreateBitmapInfoStruct(this->m_hWnd, hBMP);

			pbih = (PBITMAPINFOHEADER) pbi; 
			lpBits = (LPBYTE) GlobalAlloc(GMEM_FIXED, pbih->biSizeImage);

			if (!lpBits) 
				errhandler("GlobalAlloc", hwnd); 

			// Retrieve the color table (RGBQUAD array) and the bits  
			// (array of palette indices) from the DIB.  
			if (!GetDIBits(hDC, hBMP, 0, (WORD) pbih->biHeight, lpBits, pbi, DIB_RGB_COLORS)) 
			{
				errhandler("GetDIBits", hwnd); 
			}

			// Compute the size of the entire file.  
			hdr.bfSize = (DWORD) (sizeof(BITMAPFILEHEADER) + 
						 pbih->biSize + pbih->biClrUsed 
						 * sizeof(RGBQUAD) + pbih->biSizeImage); 

			// Compute the offset to the array of color indices.  
			hdr.bfOffBits += (DWORD) sizeof(BITMAPFILEHEADER) + 
						pbih->biSize + pbih->biClrUsed 
						* sizeof (RGBQUAD); 
		
			hdr.bfReserved1 = 0; 
			hdr.bfReserved2 = 0; 

			// Copy the BITMAPFILEHEADER into the .BMP file.  
			if (!WriteFile(hf, (LPVOID) &hdr, sizeof(BITMAPFILEHEADER), (LPDWORD) &dwTmp,  NULL)) 
			{
				errhandler("WriteFile", hwnd); 
			}

		
			//recuperer le hBITMAP et le hederindo de chq image
			HBITMAP hBMP = GetBmpUnifie(bmpListBmp[nIdImg], m_BrosseFondWizard);
			PBITMAPINFO pbi = CreateBitmapInfoStruct(this->m_hWnd, hBMP);

			pbih = (PBITMAPINFOHEADER) pbi; 
			lpBits = (LPBYTE) GlobalAlloc(GMEM_FIXED, pbih->biSizeImage);

			// Copy the BITMAPINFOHEADER and RGBQUAD array into the file.  
			if (!WriteFile(hf, (LPVOID) pbih, sizeof(BITMAPINFOHEADER) 
						  + pbih->biClrUsed * sizeof (RGBQUAD), 
						  (LPDWORD) &dwTmp, ( NULL)))
				errhandler("WriteFile", hwnd); 

			// Copy the array of color indices into the .BMP file.  
			dwTotal = cb = pbih->biSizeImage; 
			hp = lpBits; 
			if (!WriteFile(hf, (LPSTR) hp, (int) cb, (LPDWORD) &dwTmp,NULL)) 
				   errhandler("WriteFile", hwnd); 
		}//fin for
		 
		// Close the .BMP file.  
		if (!CloseHandle(hf)) 
           errhandler("CloseHandle", hwnd); 

		// Free memory.  
		GlobalFree((HGLOBAL)lpBits);
	}  
}


问题在于仅显示了图像文件.通常有3!.
我知道我错过了一些东西,但我不知道在哪里.
你能帮我告诉我哪里错了吗?
再次非常感谢您的帮助.
最好的问候.
穆拉德.


The problem is that only image file displayed. Normaly there''s 3 !.
I know I missing something but I don''t know where.
Can you help tell me where I''m wrong.
Many thanks again for your help.
Best Regards.
Mourad.


这篇关于Png图片动态创建.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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