|
| How to store and retrieve GIF,BMP and JPG in a RDBMS. | 
|
|---|
| It´s very easy to store and retrieve the most know image formats. | Product: Delphi all versions | Category: Graphic | Skill Level:
 | Scoring:  | Last Update: 03/12/2003 | Search Keys: delphi delphi3000 article borland vcl code-snippet jpg,gif,bmp,rdbms,store images. | Times Scored: 4 | Visits: 4120 | Uploader: Marcello Dias Company: | Reference: N/A | | | Question/Problem/Abstract:
You don´t have to impose your users what kind of image to use.
Specially because Gifs are better for some things(like Internet) and
JPG are better for other things(because they have a better resolution). | Answer:
Hi,
I create these functions because i wanted my systems to be able to
Lead with GIF,BMP and JPG in a transparent way for the users view.
Since i didn´t find anything ready in any book,what i did was to join
Ideas from many articles i found in the Intenet and exchange some
Ideas in the Borland Newsgroups.
I know this can be improved since the first two bytes of the image can
Identify the image type without the need od a separete field.
So if you can improve i,t be free to do so and send me an-email
In order to use GIFS you have to download the Anders Melander TGIF image
Wich is freeware.
In order to use JPG you have to include the Jpeg unit in the uses Clause.
legend
IMA_TBR_FOTO=Timage
OPD_TBR_FOTO=TOpenPictureDialog
TBR_TIPOFOTO a persistent field of the client dataset wich stores the type of the image,char(3) can be ‘JPG’,’BMP’,’GIF’
TBR_FOTO a persistent field (blob) in wich the image is stored.
=================================================================
procedure TFormTrabalhador.BtnChangeimageClick(Sender: TObject);
var
Exts : String;
begin
if OPD_TBR_FOTO.Execute then
begin
Exts := copy(AnsiUpperCase(ExtractFileExt(OPD_TBR_FOTO.FileName)),2,MaxLongInt);
if Exts = 'JPEG'
then Exts := 'JPG';
Exts:=UpperCase(Exts);
IF at(Exts,'JPG,GIF,BMP')=0 then
Begin
ShowMessage(‘this image type is not recognized’);
BtnChangeimage.SetFocus;
Exit;
end;
IMA_TBR_FOTO.Picture.LoadFromFile(OPD_TBR_FOTO.Filename);
DMClient.CLDSTrabalhador.Edit;
DMClient.CLDSTrabalhadorTBR_TIPOFOTO.AsString:=Exts;
DMClient.CLDSTrabalhadorTBR_FOTO.LoadFromFile(OPD_TBR_FOTO.Filename);
end;
end;
Procedure TFormTrabalhador.LeImagem;
var
MyJpegImage : TJpegImage;
MyGifImage : TGifImage;
MyBMP : TBitMap;
MyBlobStream:TClientBlobStream;
begin
MyBlobStream := TClientBlobStream.Create(TBlobField(DMClient.CLDSTrabalhador.FieldByName('TBR_foto')),bmRead);
try
if not(DMClient.CLDSTrabalhador.FieldByName('TBR_FOTO').IsNull) then
begin
if DMClient.CLDSTrabalhadorTBR_TIPOFOTO.AsString='BMP' then
begin
MyBMP:=TBitmap.Create;
MyBMP.LoadFromStream(MyBlobStream);
IMA_TBR_FOTO.Picture.Assign(MyBMP);
MyBMP.Free;
end
else if DMClient.CLDSTrabalhadorTBR_TIPOFOTO.AsString='JPG' then
begin
MyJPegImage := TJPegImage.Create;
MyJPegImage.LoadFromStream(MyBlobStream);
IMA_TBR_FOTO.Picture.Assign(MyJPegImage);
MyJPegImage.Free;
end
else
begin
MyGifImage := TGifImage.Create;
MyGifImage.LoadFromStream(MyBlobStream);
IMA_TBR_FOTO.Picture.Assign(MyGifImage.Bitmap);
MyGifImage.Free;
end;
end
else
IMA_TBR_FOTO.Picture.assign(Nil);
finally
MyBlobStream.Free;
end;
end;
|
|