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
 
#3

AW: IThumbnailCache - Thumbnail ermitteln

  Alt 17. Jan 2013, 15:07
image3.Picture.Bitmap.Handle := hbmp;

Ich bin nicht sicher ob das reicht, ich verwende für DIB per handle eine extra funktion die aus dem Handle ein richtiges TBitmap macht.

Delphi-Quellcode:

//*****************************************************************************************
// efg, June 2000. efg's Computer Lab, www.efg2.com/Lab
//
// Contents
//
// Method 2. hDIB to TBitmap resulting in bmDIB using MemoryStream (best)
//
// Summary:
//
// Method 1. hDIB to TBitmap resulting in bmDDB using StretchDIBits
// Method 2. hDIB to TBitmap resulting in bmDIB using MemoryStream
// Method 3. pf24bit TBitmap created using L_PaintDC Lead API call
//
// Tests:
//
// A. Deer.BMP, 160 by 194, 8 bits/pixel, palette mostly of browns
//
// 256 color display true color display (24-bit)
// 400 MHz Pentium 166 MHz Pentium
// ------------------ -----------------
// Method 1 15 ms always works 12 ms white bar (~10%) 1 of 4 times
// Method 2 7 ms always works 4 ms always works
// Method 3 6 ms bad color 21 ms bad color
//
//
// B. Balloons.BMP, 768 by 512, 24 bits/pixel, no palette
//
// 256 color display true color display (24-bit)
// 400 MHz Pentium 166 MHz Pentium
// ------------------ -----------------
// Method 1 82 ms bad color 189 ms always works.
// Method 2 74 ms OK color 261 ms always works
// Method 3 155 ms bad color 289 ms always works
//
// ============================================================================
// Method 2. hDIB to TBitmap resulting in bmDIB using MemoryStream.
// Anatomy of a DIB written to stream :
// 1. Bitmap File Header. Normally 14 bytes, i.e., SizeOf(TBitmapFileHeader).
// 2. Bitmap Info Header. Normally 40 bytes, i.e., SizeOf(TBitmapInfoHeader)
// 3. Color Table. Bitmaps with > 256 colors do not have a color table.
// 4. Bitmap Bits.
//
// Based on 12 July 1998 UseNet post "DIB to TBitmap" by Taine Gilliam in
// borland.public.delphi.vcl.components.using

function hDIBToTBitmap(const hDIB: THandle): TBitmap;

var
  BitCount: INTEGER;
  BitmapFileHeader: TBitmapFileHeader;
  BitmapInfo: pBitmapInfo;
  DIBinMemory: Pointer;
  MemoryStream: TMemoryStream;
  NumberOfColors: INTEGER;
begin
  RESULT := TBitmap.Create;

  DIBinMemory := GlobalLock(hDIB);
  try
    BitmapInfo := DIBInMemory;
    NumberOfColors := BitmapInfo.bmiHeader.biClrUsed;
    BitCount := BitmapInfo.bmiHeader.biBitCount;
    if (NumberOfColors = 0) and (BitCount <= 8) then
      NumberOfColors := 1 shl BitCount;

    with BitmapFileHeader do
      begin
        bfType := $4D42; // 'BM'
        bfReserved1 := 0;
        bfReserved2 := 0;
        bfOffBits := SizeOf(TBitmapFileHeader) +
          SizeOf(TBitmapInfoHeader) +
          NumberOfColors * SizeOf(TRGBQuad);
        bfSize := bfOffBits + BitmapInfo.bmiHeader.biSizeImage;
      end;

    MemoryStream := TMemoryStream.Create;
    try
      MemoryStream.Write(BitmapFileHeader, SizeOf(TBitmapFileHeader));
      MemoryStream.Write(DIBInMemory^,
        BitmapFileHeader.bfSize - SizeOf(TBitmapFileHeader));
      MemoryStream.Position := 0;
      RESULT.LoadFromStream(MemoryStream)
    finally
      MemoryStream.Free
    end

  finally
    GlobalUnlock(hDIB);
    GlobalFree(hDIB)
  end
end {hDIBToTBitmap};
  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 08:07 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