You are not logged in.
Pages: 1
Thanks for a great library.
Here are a two changes that I've made for my use that I think other might find usefull.
procedure TSynPicture.AssignTo(Dest: TPersistent);
begin
//This currently only handles TBitmap but could/should be extended for other TGraphic Classes
if Dest is TBitmap then
begin
TBitmap(Dest).Assign(Self.ToBitmap);
//This block is not really necessary. I've left it here for the completeness of my change
if TBitmap(Dest).PixelFormat = pfDevice then
begin
if Self is TPngImage then
TBitmap(Dest).PixelFormat := pf32bit //Possibly Alpha Transaparancy
else if Self is TGifImage then
TBitmap(Dest).PixelFormat := pf8bit //Palletted Image
else //TTiffImage, TJpegImage
TBitmap(Dest).PixelFormat := pf24bit; //Everything else
end;
end
else
Inherited;
end;
The above code allows for the common usage of assigning a TGraphic class to another TGraphic Class
For Example:
var
wBMP : TBitmap;
begin
wBMP := TBitmap.create;
try
...
//wPic is a TImage, and then Graphic is a TSynPicture descendant class (TTiffImage for example )
wBMP.Assign( wPic.Picture.Graphic );
...
Finally
wBMP.free;
end;
end;
The other change is in the ability to Define registering only specific TSynPicture classes
The following block should go under the NOTSYNPICTIREREGISTER define at the top of the file
{ if NOTSYNPICTUREREGISTER is not defined then the following has no effect }
{$define RegisterIndividualFormats}
{if RegisterIndividualFormats is not defined then all of the file formats are registered }
{ if RegisterIndividualFormats is defined then the following defines will register the appropriate TGraphic classes }
{$define RegisterTIFF}
{.$define RegisterJPEG}
{.$define RegisterPNG}
{$define RegisterGIF}
The following block should replace the If GetClass('TTiffImage') = nil then block of code in then RegisterPictures method
{$ifdef RegisterIndividualFormats}
{$ifdef RegisterJPEG}
RegisterClass(TJpegImage);
TPicture.RegisterFileFormat(PicturesExt[0], PictureName(PictureClasses[0]), PictureClasses[0]);
TPicture.RegisterFileFormat(PicturesExt[1], PictureName(PictureClasses[1]), PictureClasses[1]);
{$endif}
{$ifdef RegisterPNG}
RegisterClass(TPngImage);
TPicture.RegisterFileFormat(PicturesExt[2], PictureName(PictureClasses[2]), PictureClasses[2]);
{$endif}
{$ifdef RegisterGIF}
RegisterClass(TGifImage);
TPicture.RegisterFileFormat(PicturesExt[3], PictureName(PictureClasses[3]), PictureClasses[3]);
{$endif}
{$ifdef RegisterTIFF}
RegisterClass(TTiffImage);
TPicture.RegisterFileFormat(PicturesExt[4], PictureName(PictureClasses[4]), PictureClasses[4]);
TPicture.RegisterFileFormat(PicturesExt[5], PictureName(PictureClasses[5]), PictureClasses[5]);
{$endif}
{$else}
// register JPG and PNG pictures as TGraphic
if GetClass('TTiffImage')=nil then
begin
RegisterClass(TJpegImage);
RegisterClass(TPngImage);
RegisterClass(TGifImage);
RegisterClass(TTiffImage);
for i := 0 to high(PicturesExt) do
TPicture.RegisterFileFormat(PicturesExt[i],
PictureName(PictureClasses[i]),PictureClasses[i]);
end;
{$endif}
Hopefully other people find this useful.
Ryan.
Last edited by sllimr7139 (2012-03-29 16:57:01)
Offline
Hello,
I would like to see the Dynamic loading, so I could check like
if SynGDIPlusInstalled then
begin
// GDI+ Code in here
end;
Because sometimes we have to deal with very old computers in some lines of business. So this would make to support GDI+ in some places in same code.
-Tee-
Offline
The library is already dynamic loaded.
It is implemented to work as this: write your drawings in a TMetaFile canvas, then render it using function LoadFrom() or DrawEmfGdip().
If GDI+ is not installed, it will use GDI rendering.
If GDI is installed, it will use GDI+ rendering.
So you do not have to check for the presence of GDI+ library by yourself: the unit does it for you, and select the best available rendering method.
You can always provide the gdiplus.dll library to your customer applications. See Microsoft license about it.
Even on older Windows, our unit is able to retrieve any installed version embedded with Microsoft Office, which is likely to be installed.
You can test by hand the presence of GDI+ by using GdiP.Exists property.
Offline
Thank you very much for sharing your great work!
I'm a new here and just got the demo. The sample code refer to some emf files located on disk d:\temp\1\*.emf. I don't know is it a bit of information for you folks or just much less. Can I fix it if no one complains?
Last edited by oberon2012 (2012-11-30 15:56:12)
Offline
Thanks! I've added to zip few EMF files and tune file names in demo. How can I post/upload it?
Offline
Pages: 1