MySQL Forums
Forum List  »  Delphi

Re: Saving a Bitmap Image to a Blob
Posted by: samran wanont
Date: July 04, 2006 08:10PM

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.

Options: ReplyQuote


Subject
Written By
Posted
March 28, 2006 09:23PM
April 01, 2006 09:01PM
Re: Saving a Bitmap Image to a Blob
July 04, 2006 08:10PM


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.