Adding a JPEG graphics processing function using Delphi for Visual C ++

zhaozj2021-02-08  230

Using Delphi to add JPEG graphic processing function Visual C for JPEG, the support of JPEG, is not enough to be a defect for people, compare, Delphi / C Builder is much stronger in this area. Since JPEG is a graphic format that is often used in practical applications. If you are Visual C users, you will naturally want to make Visual C to process JPEG graphics. Although there are many Visual C libraries that can handle JPEG graphics, someone else is a bit not solely, and there are often some restrictions, such as the famous ImageObject library requires static link to MFC DLL, give Use a lot of inconveniences; if it is ActiveX control, you have to consider how to register and other troublesome problems. In fact, with the power of Delphi's powerful processing function, write a small piece of code, you can make Visual C in a few minutes to use JPEG, DIY feelings are different! To use the code introduced in this article, your hand should have a delphi (3.0 or more version) and a set of Visual C (5.0 or more versions). Since the code in this article is very simple, the following code is not commented, I believe that friends who have a slightly basis for the two languages ​​are not difficult to understand. Create a DLL project imageLib in Delphi and add a mainfn.pas unit.

File list is as follows: // ImageLib.dpr project content library ImageLib; uses SysUtils, Classes, MainFn in 'MainFn.pas'; exports CreateJPEGImage, LoadJPEGImage, FreeJPEGImage, DrawJPEGImage; begin end /// // MainFn.pas unit contents /. // unit MainFn; interface uses SysUtils, Classes, Windows, Graphics, JPEG; function CreateJPEGImage: TJPEGImage; stdcall; export; function LoadJPEGImage (image: TJPEGImage; szFileName: PChar): LongBool; stdcall; export; procedure FreeJPEGImage (image: TJPEGImage ); stdcall; export; procedure DrawJPEGImage (hdc: HDC; x, y: integer; image: TJPEGImage); stdcall; export; implementation function CreateJPEGImage: TJPEGImage; var image: TJPEGImage; begin try image: = TJPEGImage.Create; result: = image; except result: = nil; end; end; function LoadJPEGImage (image: TJPEGImage; szFileName: PChar): LongBool; var strFileName: string; begin try strFileName: = StrPas (szFileName); image.LoadFromFile (strFileName); result : = True; Except results: = false; end; end; procedure freejpegimage (image: tjpegimage); begin image.free; end; proce Dure Drawjpegimage (HDC: hdc; x, y: integer; image: tjpegimage); var canvas: tcanvas; begin canvas: = tcanvas.create; canvas.handle: = hdc; canvas.draw (x, y, image); canvas .Free; end; end. The DLL generated after the completion of the project compiles can be used directly in Visual C .

转载请注明原文地址:https://www.9cbs.com/read-1803.html

New Post(0)