delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
498 Users Online NOW
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback





Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi



Loremo - the 1.5 liter car coming in 2009




Startblatt.de






Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (3)


How to store and retrieve GIF,BMP and JPG in a RDBMS.Format this article printer-friendly!Bookmark function is only available for registered users!
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;





Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment
Still useful but...
    Marcello Dias (Oct 9 2005 9:18PM)

Hi,

I think the code above can be usefull for some special cases,
but the dataware component named  umDbImage is a really more
fancy and less verbose way of using BMP´S,GIF´S AND JPEGS.

http://www.torry.net/pages.php?id=533&SID=4b985a71858357daa662e9ee14cac6d7

You will also need a copy of Anders
Anders Melander´s GifImage program

http://www.components4programmers.com/products/kbmwabd/download.htm


Marcello
Respond

Easy way
    Mike Shkolnik (Mar 26 2003 2:40PM)

Maybe I missed something but you may simply assign your BLOB to TImage without temporary stream creation:
yourImage.Picture.Assign(TBlobField(yourGraphicalField));

Respond

RE: Easy way
Marcello Dias (Mar 26 2003 8:35PM)

Hi Mike,

Maybe i´m missing something,but in my tests the method you sugest will only work with BMP´S,It won´t work both with Gifs and Jpgs.
But if you can make it work,send me your code every line saved,and every memory saved interests me.
In fact this functions i wrote are more empirical than any other thing.

Regards,
Marcello
Respond














 
Sign up to consume product discounts for Bronze memberships !

read more


  Visit our Sponsor

 

  Community Ad of
Hans Gulö
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)