procedure TForm1.ZeigeBitmap;
var Bmp:TBitmap; Stream : TMemoryStream; FStream:TFileStream; BildAnz:integer;
const Verz = '
C:\Temp\'; JPGDatei = '
Test.JPG'; BMPDatei = '
Test.bmp'; DBDatei = '
Test.db';
begin
// Bitmap laden
Bmp := TBitmap.Create;
Bmp.LoadFromFile(Verz + BMPDatei);
// Auf Form zeichnen
Self.Canvas.Draw(10,10,Bmp);
// In DB speichern
FStream := TFileStream.Create(Verz + DBDatei,fmCreate);
BildAnz := 1;
FStream.WriteData(BildAnz);
Bmp.SaveToStream(FStream);
FStream.Free;
Bmp.Free;
// Wieder laden und anzeigen
Bmp := TBitmap.Create;
Stream := TMemoryStream.Create;
Stream.LoadFromFile(Verz + DBDatei);
Stream.ReadData(BildAnz);
Bmp.LoadFromStream(Stream);
Self.Canvas.Draw(10,250,Bmp);
Bmp.Free;
// Thumbnail aus JPG-Datei
Bmp := TBitmap.Create;
ExtractThumbnail(Bmp,Verz + JPGDatei,400,0);
// Auf Form zeichnen
Self.Canvas.Draw(450,10,Bmp);
// In DB speichern
FStream := TFileStream.Create(Verz + DBDatei,fmCreate);
BildAnz := 1;
FStream.WriteData(BildAnz);
Bmp.SaveToStream(FStream);
FStream.Free;
Bmp.Free;
// Wieder laden und anzeigen
Bmp := TBitmap.Create;
Stream := TMemoryStream.Create;
Stream.LoadFromFile(Verz + DBDatei);
Stream.ReadData(BildAnz);
Bmp.LoadFromStream(Stream);
Self.Canvas.Draw(450,250,Bmp);
Bmp.Free;
Stream.Free;
end;
procedure ExtractThumbnail(Bitmap:TBitmap; FileName:
string; DesiredWidth:integer; DesiredHeight:integer);
var
Malloc:IMalloc;
DesktopFolder,SourceFolder:IShellFolder;
eaten,flags,prio:cardinal;
id:PItemIDList;
ex:IExtractImage;
s:TSize;
h:HBITMAP;
w:WideString;
begin
try
OleCheck(SHGetMalloc(Malloc));
OleCheck(SHGetDesktopFolder(DesktopFolder));
flags:=0;
w:=ExtractFilePath(FileName);
OleCheck(DesktopFolder.ParseDisplayName(0,
nil,PWideChar(w),eaten,id,flags));
try
OleCheck(DesktopFolder.BindToObject(id,
nil,IShellFolder,SourceFolder));
finally
Malloc.Free(id);
end;
w:=ExtractFileName(FileName);
OleCheck(SourceFolder.ParseDisplayName(0,
nil,PWideChar(w),eaten,id,flags));
If SourceFolder.GetUIObjectOf(0,1,id,IExtractImage,
nil,ex) <> S_OK
then exit;
s.cx:=DesiredWidth;
s.cy:=DesiredHeight;
If (s.cx > 160)
or (s.cy > 90)
then flags:=IEIFLAG_SCREEN
or IEIFLAG_OFFLINE
or IEIFLAG_QUALITY
or IEIFLAG_ORIGSIZE
else flags:=IEIFLAG_SCREEN
or IEIFLAG_OFFLINE
or IEIFLAG_QUALITY;
prio:=0;
SetLength(w,MAX_PATH);
OleCheck(ex.GetLocation(PWideChar(w),Length(w)*2,prio,s,32,flags));
OleCheck(ex.Extract(h));
Bitmap.Handle:=h;
finally
Malloc.Free(id);
DesktopFolder:=nil;
SourceFolder:=nil;
Malloc:=nil;
end;
end;