You are not logged in.
Pages: 1
Hi,
I need save a PNG (with transparent) on a field of my database and the load it to show on my form.
I think I can use the code write for bitmap:
SAVE:
var
doc: RawByteString;
begin
SaveAsRawByteString(imgDocument.Picture,doc,gptPNG,80,1500);
Database.UpdateBlob(TSQLContacts, Contact.ID, 'Document', doc);
end;
my problem is the code to LOAD the image, now in fact I use:
var
doc: TSQLRawBlob;
pic: TBitmap;
begin
Database.RetrieveBlob(TSQLContacts, Contact.ID, 'Document', doc);
Contact.Document := doc;
pic := PictureToBitmap(ContattoRecord.Document);
if pic <> nil then
begin
image.Picture.Bitmap.Assign(pic);
pic.Free;
end;
end;
Where PictureToBitmap is:
function PictureToBitmap(const Picture: RawByteString): TBitmap;
var
ST: THeapMemoryStream;
begin
Result := nil;
if Picture='' then
exit;
ST := THeapMemoryStream.Create;
try
ST.Write(pointer(Picture)^,length(Picture));
with TSynPicture.Create do
try
LoadFromStream(ST);
result := ToBitmap;
finally
Free;
end;
finally
ST.Free;
end;
end;
Is there a way to get a PNG and not a BMP? In PictureToBitmap there is ToBitmap to get a bitmap, but for other images format?
Offline
Just use something like this in the code:
function PictureToSynPicture(const Picture: RawByteString): TSynPicture;
var
ST: TStream;
Pic: TSynPicture;
begin
Result := nil;
if Picture='' then
exit;
ST := TSynMemoryStream.Create(Picture);
try
Pic := TSynPicture.Create;
try
LoadFromStream(ST);
result := Pic;
Pic := nil;
finally
Pic.Free;
end;
finally
ST.Free;
end;
end;
That is, return the TSynPicture and not its bitmap conversion.
Offline
I have a small problem.
Today I have convert my application from Delphi 2006 to Delphi XE3.
All the code works without problem but I have a small bug, I need to use
initialization
Gdip.RegisterPictures;
to use the code above (save/load image from/to database) but with this code at runtime all my TImage with PNG image are black, if I comment this code I can see all PNG on my TImage but I cannot save/load image from/to database.
How can I solve it?
Thanks
Offline
Are there other users with the same problem? I cannot use PNG any more...
Offline
With Delphi XE3?
Please see the small demo: http://dl.dropbox.com/u/19900180/pngproblem.zip
The code is very simple:
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, SynGdiPlus, Vcl.Imaging.pngimage,
Vcl.ExtCtrls;
type
TForm1 = class(TForm)
Image1: TImage;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
initialization
Gdip.RegisterPictures;
end.
There is only a form with a PNG, on design time I can see the PNG but on run time I cannot see it (see the exe demo).
I don't understand...
Do you have some ideas?
PS with Delphi 2006 I don't have this problem.
Offline
Can someone test my demo on XE3?
Last edited by array81 (2012-11-01 22:16:40)
Offline
tested on XE2 and 2010 and same problem
Offline
Good, so it's there a bug or a problem with last version of Delphi...
On old version it's works (I have tested only on Delphi 2006).
Offline
if try assign png runtime from file or pngimagecollection i see png
too dont understand why enable Gdip.RegisterPictures; dont show png
Offline
in fact. for the moment I have convert my png to bitmap 32bit so can avoid the problem. I hope this bug will be fixed
Offline
Pages: 1