1. Bitmap Class Based on C #
Using System;
Using System. Collections. Generic;
Using System. text;
Using System. IO;
Using System. drawing;
Using System. Drawing. imaging;
Namespace Lelebmp tojpeg
{
Class Program
{
Static Void Main ( String [] ARGs)
{
String BMP filepath = " Testbmp .bmp " ;
Bitmap m_bitmap = New Bitmap (BMP filepath ); // Reads bitmap files in a specified directory and constructs bitmap objects.
String Jpgfilepath = " Jpegresult.jpg " ;
M_bitmap.save (jpgfilepath, imageformat. JPEG ); // Save image files
// Note:
// 1. There are many other options for saving the image format, such as GIF and PNG.
// 2. You can save the conversion result as a file stream or a memory stream.
}
}
}
Note: This method can only be used in WINXP. In wince, the bitmap statement cannot run normally. I don't know why, it may be that such advanced functions are not provided in wince. Finally, the format is converted using C ++ through the iimagefactory interface.
II. C ++-based ATL support class cimage
Use vs2005 to create C ++ in WINXPProgramAnd select the ATL support when creating the program.
Then, in the main fileCodeAs follows:
// Winxpcppatl. cpp: defines the entry point of the console application. // # Include "stdafx. H "# include" winxpcppatl. H "# include <atlimage. h> // Cyan: header file of the cimage class # ifdef _ debug # define new debug_new # endif // unique application object cwinapp theapp; using namespace STD; int _ tmain (INT argc, tchar * argv [], tchar * envp []) {int nretcode = 0; // initialize MFC and display an error if (! Afxwininit (: getmodulehandle (null), null,: getcommandline (), 0) {// todo: change the error code to meet your needs _ tprintf (_ T ("error: MFC initialization failed \ n"); nretcode = 1;} else {// todo: write code for the behavior of the application here. Cimage m_image; m_image.load (_ T ("\ recvbmp data.bmp"); m_image.save (_ T ("\ recvbmp data.jpg");} return nretcode ;}
Note: This method can be used for file operations or in-memory transcoding operations, but it can only be performed under WINXP and cannot be successful under wince. Although the ATL in wince also has this cimage class, the method provided is limited than that in XP, and cannot meet the format conversion requirements in the wince platform.