Load Gambar Menggunakan Delphi

Dapet lagi dari forum delphi-id[dot]org, kebetulan yang posting adalah master delphi sekaligus moderator yang handal di forum. Mumpung masih hangat dan belum hilang dari daftar aku langsung salin deh, berikut salinannya:

Kitik-kitik berikut mungkin dapat dipertimbangkan Smile

  1. function LoadJPEGImage(const Source: TField; const Dest: TPicture): Boolean;
  2. var Temp: TStream;
  3. Img: TJPEGImage;
  4. begin
  5. Result:= (Source is TBlobField) and (Source.Size > 0); // is greather than zero?
  6. if Result then
  7. begin
  8. Temp:= TMemoryStream.Create;
  9. try
  10. TBlobField(Source).SaveToStream(Temp);
  11. Temp.Seek(0, soFromBeginning);
  12. Dest.Graphic:= nil;
  13. Img:= TJPEGImage.Create;
  14. try
  15. Img.LoadFromStream(Temp);
  16. Dest.Graphic:= Img;
  17. except
  18. if not Assigned(Dest.Graphic) then
  19. FreeAndNil(Img)
  20. else
  21. Dest.Graphic:= nil;
  22. Result:= False;
  23. end;
  24. finally
  25. FreeAndNil(Temp);
  26. end;
  27. end;
  28. end;

Penggunaan:

  1. begin
  2. if not LoadJPEGImage(DM.QueIklan2Level1, Image1.Picture) then
  3. raise Exception.Create('Cannot load image!');
  4. end;

Bagi yang berminat, silahkan langsung kopi….

Advertisements

2 Responses to “Load Gambar Menggunakan Delphi”

  1. dony Says:

    thanks mas buat infonya, ijin copy paste nih hehe buat koleksi…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: