AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Win32/Win64 API (native code) Delphi IThumbnailCache - Thumbnail ermitteln
Thema durchsuchen
Ansicht
Themen-Optionen

IThumbnailCache - Thumbnail ermitteln

Ein Thema von Andreas L. · begonnen am 15. Jan 2013 · letzter Beitrag vom 27. Jan 2013
 
KarstenK

Registriert seit: 4. Dez 2007
Ort: Bärenthal
29 Beiträge
 
Delphi 2009 Enterprise
 
#10

AW: IThumbnailCache - Thumbnail ermitteln

  Alt 20. Jan 2013, 16:57
Hallo,

so klappt das.


Delphi-Quellcode:
procedure FlipBitmap(Bitmap: Tbitmap);
var
  i, j: integer;
  P1, p2: Pbyte;
  bs: byte;
  BytesPerLine: integer;
begin
  case Bitmap.PixelFormat of
    // pfDevice: ;
    pf1bit: BytesPerLine := (Bitmap.Width - 7) div 8 +1; //richtig?
    pf4bit: BytesPerLine := (Bitmap.Width - 1) div 2 +1; //richtig?
    pf8bit: BytesPerLine := Bitmap.Width;
    pf15bit: BytesPerLine := 2 * Bitmap.Width;
    pf16bit: BytesPerLine := 2 * Bitmap.Width;
    pf24bit: BytesPerLine := 3 * Bitmap.Width;
    pf32bit: BytesPerLine := 4 * Bitmap.Width;
    // pfCustom: ;
  end;

  for I := 0 to Bitmap.Height div 2 - 1 do
    begin
      P1 := Bitmap.ScanLine[i];
      P2 := Bitmap.ScanLine[Bitmap.Height - 1 - i];
      for j := 0 to BytesPerLine - 1 do
        begin
          bs := P1[j];
          P1[j] := P2[j];
          P2[j] := bs;

          inc(p1);
          inc(p2);
        end;
    end;
end;


function GetThumbFromCache1(AFileName: string; AMaxSize: Integer = 120): TBITMAP;
var
  thumbcache: IThumbnailCache;
  sharedbmp: ISharedBitmap;
  shellitem: IShellItem;
  // thumbflags: PWTS_CACHEFLAGS;
  // thumbid: PWTS_THUMBNAILID;
  // thumbsize: TSize;
  hBmp: HBITMAP;
begin
  CoInitialize(nil);
  result := nil;
  try
    if Succeeded(CoCreateInstance(CLSID_LocalThumbnailCache, nil, CLSCTX_INPROC, IThumbnailCache, thumbcache)) then
      if Succeeded(SHCreateItemFromParsingName(PChar(AFileName), nil, IShellItem, shellitem)) then
        if Succeeded(thumbcache.GetThumbnail(shellitem, AMaxSize, WTS_EXTRACT, sharedbmp, nil, nil)) then
          if Succeeded(sharedbmp.GetSharedBitmap(hBmp)) then
            begin
              result := Tbitmap.Create;
              result.Handle := hbmp;
              result.Dormant; //extrem wichtig, sonst stimmen zwar METADATEN, aber das Handle ist kaputt
              //flip , sonst auf dem Kopf
              FlipBitmap(result);
            end;
  finally
    CoUninitialize;
  end;
end;


procedure TForm10.Button1Click(Sender: TObject);
var TB:graphics.Tbitmap;
begin
 if OpenDialog1.execute then
  Try
    TB:= GetThumbFromCache1(OpenDialog1.FileName,120);
    Image1.Picture.Assign(TB);
  finally
    TB.Free;
  end;
end;
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 12:46 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz