You are not logged in.
Our freeware SynGdiPlus unit implements TGraphic descendants able to load and save GIF, TIF, PNG and JPG pictures, using the GDI+ library.
Freeware Opensource component, licensed under a MPL/GPL/LGPL tri-license.
Works from Delphi 3 to 2010.
By adding the SynGdiPlus unit to your uses clause, some new TGraphic descendants are registered in your application to load GIF, TIF, PNG and JPG pictures. Use TPicture.LoadFromFile() method with the right extension, and the corresponding decoder will be used.
This unit implements its own GDI+ API functions, in a safe dynamic manner. Even if you don't have GDI+ installed on the system (e.g. with Windows 2000), the executable will launch - but all GIF, TIF, PNG and JPG pictures loading and saving won't work. Please note that the GDI+ library is available on all Windows Operating System since Windows XP (including Vista and Seven).
Since all the decoding and encoding is done by the GDI+ library, this unit adds much less code to your executable than the standard JPEG and PNG units.
These classes handle the saving of the pictures. Most GDI+ implementation just allows you to load pictures. This unit handle all the saving and conversion between formats. You can easily load an TIF, then save it as a JPG file with a specified Compression Quality, via the SaveAs() method.
Some easy one line helper functions are available:
function LoadFrom(const FileName: TFileName): TBitmap;
procedure SaveAs(Graphic: TPersistent; Stream: TStream; Format: TGDIPPictureType; CompressionQuality: integer=80); overload;
procedure SaveAs(Graphic: TPersistent; const FileName: TFileName; Format: TGDIPPictureType; CompressionQuality: integer=80); overload;
The full source code of this unit (intended to work from Delphi 3 to 2010) is freely downloadable from http://synopse.info/files/SynGdiPlus.zip, or as part of Synopse SQLite3 framework.
Offline
I've uploaded an updated version to the http://synopse.info/files/SynGdiPlus.zip archive file.
It was still in version 1.6.... now you've got the latest version, that is 1.9.
Offline
I've uploaded a 1.12 version, from the main SQLite3 framework package.
Here are the enhancements:
- added code for error handling, via new TGdipStatus enumeration type;
- now GDI+ handles are stored using THandle instead of plain integer type (in order to prepare a 64 bit version of the unit);
- fixed a problem in rendering bitmaps, e.g. as created in SQLite3Pages;
- fixed a problem in rendering underlined text (GDI+ DrawDriverString doesn't handle underlined or stroken out fonts as expected).
Offline
Problem using SynGDI+
You state: By adding the SynGdiPlus unit to your uses clause, some new TGraphic descendants are registered in your application to load GIF, TIF, PNG and JPG pictures. Use TPicture.LoadFromFile() method with the right extension, and the corresponding decoder will be used.
I used your TestSynGdiPlus app (works fine for .emf files), and dropped a Button on the form.
In the ButtonClick, I Add this:
img1.Picure.LoadFromFile('c:\test.png');
and I get the following error:
Unknown picture file extension (.png)
What am I doing wrong?
Offline
I found a way that works:
procedure TForm1.Button1Click(Sender: TObject);
var
pic: TPngImage;
begin
pic := TPngImage.Create;
pic.LoadFromFile('C:\Users\christian.landman\Pictures\MotaData.png');
img1.Picture.Bitmap := pic.ToBitmap;
end;
This works just fine - thank you! (Using Delphi 6 Enterprise - All updates loaded)
I'm just a bit disapointed that it doesn't work the way you say it does...
Offline
hmmm, except of the memory leaks, cause the pic Instance will never be freed
Offline
Re: Memory Leak
Thank you Sir Rufo and Mr. Administrator
Offline
I am trying to use the SynGDIPlus in Delphi7 and Win7 to load a jpg file but I can´t do it work.
First I tried
jpg.LoadFromFile('d:\teste.jpg');
Image.Picture.Bitmap := jpg.Bitmap
After I tried to undefine the NOTSYNPICTUREREGISTER and use
image.Picture.LoadFromFile('d:\teste.jpg')
In both cases, no error given but the image don´t renderize anything on screen.
If I use the original TJPEGImage and use this code, it works
var
jpg.LoadFromFile('d:\teste.jpg');
Image.Picture.Bitmap.Assign(jpg)
Any clues ?
Offline
Try using it like that:
Image.Picture.Graphic := TPngImage.Create;
TPngImage(Image.Picture.Graphic).LoadFromResourceName(HInstance,'wizard2');
That is, use directly the Image.Picture.Graphic and not the Image.Picture.Bitmap property.
It will also be faster, since it will draw it directly to the canvas, no via a temporary bitmap.
Offline
I have the same result.
No error in the process but the image does not render in the container canvas ( a TPanel ). Any other idea ?
Offline
Post some code to reproduce the issue.
It is working in a lot of programs, so we need to know what is wrong with your code, or find out if there is any error in our unit.
Offline
AB, Your code work as intended. I did a new project with only a button and a TImage and it worked as you pointed.
After inspecting my project where I am creating the TImage on runtime I found my error and now I can use what I expected:
Image.Picture.LoadFromFile('D:\test.jpg')
and it is working !
Thank you for you help
Last edited by Rogeriouk (2012-03-16 21:42:49)
Offline
I look forward to using these units!
I'm running Win7 Pro 64-bit, compiling under D7Pro 7.2. I'm trying to use the LoadFromFile routine. Tracing through your code, I get stopped at line 1200:
if not Gdip.Exists or not FileExists(FileName) then
exit;
Tracing through it looks through the function [Exists] returns, but then immediately jumps to the end of the LoadFromFile routine. Doesn't even hit the EXIT command.
So I tried changing the logic of the code, JUST to make sure.
procedure TSynPicture.LoadFromFile(const FileName: string);
var FS: TFileStream;
begin // don't use direct GDI+ file oriented API: it's better having a local
// copy of the untouched data in memory (e.g. for further jpeg saving)
Clear;
if (Gdip.Exists) then
if (FileExists(FileName)) then begin
FS := TFileStream.Create(FileName,fmOpenRead or fmShareDenyNone);
try
LoadFromStream(FS);
finally
FS.Free;
end;
end;
end;
So apparently GDIP actually doesn't exist? It goes again through the function Exists, but then drops right to the end of the function.
What am I doing wrong?
Here is the code I'm using:
procedure TForm1.Button2Click(Sender: TObject);
var
Pic:TSynPicture;
const fname='C:\Users\Stephen\Dropbox\Photos\Grand Am\DSC00824.jpg';
begin
Pic:=TSynPicture.Create;
Pic.LoadFromFile(fname);
Image1.Picture.Graphic:=Pic;
image2.Picture.LoadFromFile(fname);
end;
Image2 does render the image.
Last edited by Pontiac (2012-06-24 03:59:09)
Offline
Read the documentation about SynGDIPlus unit, or even just read the interface part of it:
var
/// GDI+ library instance
// - only initialized at program startup if the NOTSYNPICTUREREGISTER is NOT
// defined (which is not the default)
// - Gdip.Exists return FALSE if the GDI+ library is not available in this
// operating system (e.g. on Windows 2000) nor the current executable folder
Gdip: TGDIPlus = nil;
To use pictures in your code, you will need to call once:
Gdip.RegisterPictures; // will initialize the Gdip library if necessary
Offline
Thanks for the heads up. I undefined the compiler directive, re-ran, and now I have a successful result.
But I'm having an issue trying to get a JPG that is in a stream into a graphic. I'm going to play some more before I whine about something else I didn't read about. {smirk}
Edit: Over thought things at this end. All working as intended. TYVM.
Last edited by Pontiac (2012-06-25 09:30:14)
Offline
Hello,
Would it be possible to make SynGDIPlus (if not already) dynamic so it programs without GDI+ (Old ones), would not crash... So program could disable some features dynamically or inform user, to try to install GDI+ (or someting similar)...
I have made dynamic version of some Gdi+ Delphi implementation, but seems that it will not compile in D2010+ so, would like to have some implementation that would work for DD7 and D2010, before we can jump away from the D7.
-Tee-
Offline
This is already the case.
Loading is made dynamically, and it is able to find the best available GdiPlu.dll library (e.g. link to the one supplied with Microsoft Office, if it is newer than the one included within XP).
In fact, the program has to check for GDIPlus availability, and use anti-aliaised drawing only if available.
Offline
Dear synopse,
I need to show the .tif format but
I've a problem when try to open TestSynGDIPlus.dpr
There is an error showed up : "Cannot find resource file "d:/TestSynGDIPlus.res. Recreated."
Please some advices.
Many Thank's.
Offline
Hello,
Is there a way to support the Zip or deflate compression method with Tiff images ?
Kind regards
Frederic
Last edited by fs999 (2016-04-29 12:04:17)
Offline