Re: Saving a Bitmap Image to a Blob
procedure AddPicture1Click(Sender: TObject);
var //bmp:tpicture;
Jpg: TJpegImage;
Stream: TMemoryStream;
FileExt: string;
GraphType: TGraphType;
begin
if dlgOpenPicture.Execute then
begin
Jpg := nil;
Stream := nil;
try
Stream := TMemoryStream.Create;
FileExt := LowerCase(ExtractFileExt(dlgOpenPicture.FileName));
if (FileExt = '.bmp') or (FileExt = '.dib') then
begin
GraphType := gtBitmap;
Stream.Write(GraphType, 1);
with Image1.Picture.Bitmap do
begin
LoadFromFile(dlgOpenPicture.FileName);
Image1.Picture.Bitmap.SaveToStream(Stream);
end;
end else
if (FileExt = '.ico') then
begin
GraphType := gtIcon;
Stream.Write(GraphType, 1);
with Image1.Picture.Icon do
begin
LoadFromFile(dlgOpenPicture.FileName);
Image1.Picture.Bitmap.SaveToStream(Stream);
end;
end else
if (FileExt = '.emf') or (FileExt = '.wmf') then
begin
GraphType := gtMetafile;
Stream.Write(GraphType, 1);
with Image1.Picture.Metafile do
begin
LoadFromFile(dlgOpenPicture.FileName);
Image1.Picture.Bitmap.SaveToStream(Stream);
end;
end else
if (FileExt = '.jpg') or (FileExt = '.jpeg')
or (FileExt = '.jpe') then
begin
Jpg := TJpegImage.Create;
Jpg.LoadFromFile(dlgOpenPicture.FileName);
Image1.Picture.Assign(Jpg);
GraphType := gtJpeg;
Stream.Write(GraphType, 1);
Jpg.SaveToStream(Stream);
end;
Stream.Position := 0;
TBlobField(cdItem.FieldByName('pict')).LoadFromStream(Stream);
except
jpg.Free;
Stream.Free;
raise;
end;
jpg.Free;
Stream.Free;
end;
end;
Edited 1 time(s). Last edit at 07/04/2006 08:11PM by samran wanont.
Subject
Written By
Posted
Re: Saving a Bitmap Image to a Blob
July 04, 2006 08:10PM
December 28, 2006 08:13PM
December 29, 2006 05:38AM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.