Use other compiler to enhance Visual C graphics function
It is undeniable that Visual C is a very powerful programming environment. However, Visual C also has many restrictions, such as the construction of the interface and graphic processing, which is not as convenient to Delphi / BCB. However, we can use the functions provided by these compilers to make up for the shortcomings of Visual C in this regard.
I often see topics about how to load images from .BMP files and how to store images from .bmp files. BMP files. In fact, it is very simple from the image from BMP: a loadImage function call can solve the problem. But how do you store the image into the BMP file? Although I know the structure of the BMP file, I will not write a function from the head or class, which is equal to "reinvent the wheel". Although I also know that there are many such libments available now, but as a programmer, I will solve the problem more accomplishment. Here, I have a lazy way: Just write a dozen lines of code, plus a little extra step, I can get it, don't have to touch the BitmapxxxxHeader who is bullous to tertiary, do not care about the clipboard and pixel format, You don't have to consider the trip code, as long as there is a Delphi compiler. And see how I made:
Open Delphi to generate a new DLL project, export the SaveBitMaptofile function in the DLL:
unit ImageDll; interfaceusesSysUtils, Classes, Windows, Graphics; function SaveBitmapToFile (hbm: HBITMAP; szFileName: PChar): Boolean; stdcall; export; implementationfunction SaveBitmapToFile (hbm: HBITMAP; szFileName: PChar): Boolean; var bm: TBitmap; strFileName: String; begin result: = true; try bm: = tbitmap.create; try bm.handle: = HBM; strfilename: = strPas (SZFileName); bm.savetofile; Except Result: = false; end finally bm.free ; End;
how is it? Very simple? As long as you compile this DLL, my job is completed. However, it is still tested in Visual C to test the actual effect. Here is the test code added to a Dialog Based's Visual C project:
Typedef Bool (__stdcall * pfnsavebitmaptofile) (Hbitmap, LPCSTR);
Bool ctestdlg :: OnNitDialog () {m_hlib = loadingLibrary ("delphiimage.dll");} void ctestdlg :: ONDESTROY () {if (m_hlib) Freelibrary (m_hlib);}
void CTestDlg :: OnButton1 () {HBITMAP hbm = (HBITMAP) LoadImage (AfxGetInstanceHandle (), "c: // windows // Setup .bmp", IMAGE_BITMAP, 0,0, LR_LOADFROMFILE); if (hbm) {PFNSAVEBITMAPTOFILE pfnSaveBitmapToFile = (pFNSAVEBITMAPTOFILE) GetProcAddress (m_hLib, "SaveBitmapToFile"); if (pfnSaveBitmapToFile) (* pfnSaveBitmapToFile) (hbm, "c: //test.bmp"); else AfxMessageBox ( "! GetProcAddress Failed"); DeleteObject (hbm); }} As long as you have a slightly understanding of VC and Delphi, the above code should not be a problem. If you like, you can also add support to ICO, WMF, and even JPG files to the DLL! As long as you introduce the JPEG unit in Delphi's DLL project.