Delphi-PRAXiS
Seite 2 von 2     12   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi IThumbnailCache - Thumbnail ermitteln (https://www.delphipraxis.net/172650-ithumbnailcache-thumbnail-ermitteln.html)

Andreas L. 24. Jan 2013 07:26

AW: IThumbnailCache - Thumbnail ermitteln
 
Mit TBitmap.Dormant := True kann ich jetzt auf das Bild auch außerhalb der GetThumbFromCache-Funktion zugreifen. Leider bekomme ich eine Zugriffsverletzung in der Zeile bs := P1[j]; der procedure FlipBitmap:

Zitat:

---------------------------
Benachrichtigung über Debugger-Exception
---------------------------
Im Projekt Project3.exe ist eine Exception der Klasse EAccessViolation mit der Meldung 'Zugriffsverletzung bei Adresse 004ACC76 in Modul 'Project3.exe'. Lesen von Adresse 00003F00' aufgetreten.
---------------------------
Anhalten Fortsetzen Hilfe
---------------------------

Debugger:
P1 $3F00
i 0
j 0
p2 nil
BytesPerLine 256
bs E2171 Auf Variable 'bs' kann wegen Optimierung nicht zugegriffen werden

Funktioniert FlipBitmap bei dir? Was könnte der Fehler sein?

KarstenK 24. Jan 2013 09:38

AW: IThumbnailCache - Thumbnail ermitteln
 
"Mit TBitmap.Dormant := True kann ich jetzt auf das Bild auch außerhalb der GetThumbFromCache-Funktion zugreifen".

Das nuss ausgeführt werden, solange das Handle gültig ist, also innerhalb von GetThumbFromCache

Andreas L. 25. Jan 2013 05:51

AW: IThumbnailCache - Thumbnail ermitteln
 
Zitat:

Zitat von KarstenK (Beitrag 1200413)

Das nuss ausgeführt werden, solange das Handle gültig ist, also innerhalb von GetThumbFromCache

Das mache ich auch. Es wird mir von der Funktion auch ein Bild zurückgeliefert, nur steht es auf den kopf. Und wenn ich deine FlipBitmap-Funktion verwende, bekomme ich die oben genannte AV. Mein Code sieht im Moment so aus:

Delphi-Quellcode:
function TForm2.GetThumbFromCache(AFileName: string; out Bmp: TBitmap; AMaxSize: Integer = 120): HRESULT;
var
  thumbcache: IThumbnailCache;
  sharedbmp: ISharedBitmap;
  shellitem: IShellItem;
  thumbflags: PWTS_CACHEFLAGS;
  thumbid: PWTS_THUMBNAILID;
  thumbsize: TSize;
  hBmp: HBITMAP;
begin
  if not Assigned(Bmp) then
    Exit;

  Result := CoInitialize(Nil);

  Result := CoCreateInstance(
    CLSID_LocalThumbnailCache,
    nil,
    CLSCTX_INPROC,
    IThumbnailCache,
    thumbcache
  );

  if Succeeded(Result) then
  begin
    Result := SHCreateItemFromParsingName(
      PChar(AFileName),
      nil,
      IShellItem,
      shellitem
    );

    if Succeeded(Result) then
    begin
      Result := thumbcache.GetThumbnail(
        shellitem,
        AMaxSize,
        WTS_EXTRACT,
        sharedbmp,
        nil, //thumbflags,
        nil //thumbid
      );

      if Succeeded(Result) then
      begin
        sharedbmp.GetSize(thumbsize);
        Result := sharedbmp.GetSharedBitmap(hBmp);
        if Succeeded(Result) then
        begin
          bmp.SetSize(thumbsize.cx, thumbsize.cy);
          bmp.Handle := hBmp;
          bmp.Dormant;
          //FlipBmp(bmp);
          MirrorVertical(Bmp);
        end;
      end;

      CoUninitialize;
    end;
  end;
end;
Mit folgendes Funktion kann ich das Bild drehen, die soll allerdings langsam sein:

Delphi-Quellcode:
Procedure MirrorVertical(var Picture: TBitmap);
var BMP: TBitmap;
     i,j: integer;
begin
BMP := TBitmap.Create;
BMP.Assign(Picture);
for i := 0 to BMP.Height-1 do
  for j := 0 to BMP.Width-1 do
   Picture.canvas.Pixels[j, BMP.Height-i-1] := BMP.canvas.Pixels[j, i];
BMP.free;
end;

KarstenK 25. Jan 2013 14:20

AW: IThumbnailCache - Thumbnail ermitteln
 
Ja, da war noch ein Fehler (X koordinate wurde doppelt hochgezählt) drin, keine Ahnung wieso der Code bei mir damals ging.
Wobei auch die Korrektur fehlschlug.

Nach setzen auf Pixelformat pf24bit, läuft er heute wieder bei mir.


Delphi-Quellcode:
procedure FlipBitmap(VAr BitmapToFlip: Tbitmap);
var
  i, j: integer;
  P1, p2: Pbytearray;
  bs: byte;
  BytesPerLine: integer;
begin
  BitmapToFlip.PixelFormat := pf24bit;
  BytesPerLine := 3 * BitmapToFlip.Width;

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

Andreas L. 27. Jan 2013 06:47

AW: IThumbnailCache - Thumbnail ermitteln
 
Die überarbeitete Version funktioniert :thumb:

Danke für eure Hilfe :dp:


Alle Zeitangaben in WEZ +1. Es ist jetzt 00:53 Uhr.
Seite 2 von 2     12   

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz