Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi PSafeArray nach Bitmap (https://www.delphipraxis.net/69839-psafearray-nach-bitmap.html)

semo 20. Mai 2006 20:48


PSafeArray nach Bitmap
 
ich steh glaube im wald und seh die bäume nicht :pale:

ich habe ein olevariant welches ein SafeArray of Byte enthält.
Darin enthalten sind alle Bilddaten für ein Bitmap OHNE Header.

meine frage bzw aufgabe ist es nun diese daten in ein bitmap zu bekommen.

ich bekomme noch infos mitgeliefert:
breite des bildes in pixel: 826
höhe des bildes in pixel: 1168
anzahl der bytes per line: 2480
dpiX: 100
dpiY: 100
24 Bits pro pixel

an das safearray of byte komme ich bisher wie folgt heran:
Delphi-Quellcode:
...
var
  Val: PSafeArray;
begin
  ...
  val := PSafeArray(TVariantArg(aOleVariant).ppArray);
  ActiveX.SafeArrayGetLBound(Val, 1, iMin); // liefert iMin = 0
  ActiveX.SafeArrayGetUBound(Val, 1, iMax); // liefert iMax = 2896639
  ..
mit der methode CreateBitmap kann man ein bitmap aus einem solchen Array erzeugen, unter Angabe von breite, höhe, farbtiefe und anzahl der paletten:
Delphi-Quellcode:
HBITMAP CreateBitmap(
  int nWidth,        // bitmap width, in pixels
  int nHeight,       // bitmap height, in pixels
  UINT cPlanes,      // number of color planes
  UINT cBitsPerPel,  // number of bits to identify color
  CONST VOID *lpvBits // color data array
);
--> mein Code:
Delphi-Quellcode:
aTempBitmap := CreateBitmap (width, height, 1, BitsPerPixel, Val);
// width = 826
// height = 1168
// BitsPerPixel = 24



Hier ein Beispiel eines VB-Codes aus der zugehörigen Hilfedatei:
Delphi-Quellcode:
CRecImage  Image;
CRecInfo   Info;
aOleVariant vBitmap;
LPBYTE     pBitmap = NULL;
HBITMAP    hBitmap;

try
{
   . . .
   Document.SetLineOrder(TOP_DOWN);
   Document.SetPadding(PAD_WORDBOUNDARY);
   Document.SetRGBOrder(COLOR_RGB);
   aOleVariant = Image.Get(Info,0,0,160,100);
   SafeArrayAccessData(vBitmap.parray,(void **)&pBitmap);
   hBitmap = CreateBitmap(Info.GetWidth(),Info.GetHeight(), 1, Info.GetBitsPerPixel(), pBitmap);
   . . .
   SafeArrayUnaccessData(vBitmap.parray);

VariantClear(&vBitmap);
   . . .
catch(CRecException e)
{
    TRACE("Error code = %X\n", e.m_hr);
}
Wie setzt man das in Delphi um?

Khabarakh 20. Mai 2006 20:59

Re: PSafeArray nach Bitmap
 
Das ist aber ein komischer VB-Code ;) .

Das Bitmap-Handle kannst du Delphi-Referenz durchsuchenTBitmap.Handle (wow :stupid: ) zuweisen. Dann kannst du das Bitmap auf ein Image oderwasauchimmer zeichnen.

semo 20. Mai 2006 21:02

Re: PSafeArray nach Bitmap
 
okay ok ist c :P
in der hilfe werden vb und c codes verwendet.
nur leider kein einziges delphibeispiel.

das mit dem zuweisen habe ich im anschluss auch gemacht:
Delphi-Quellcode:
aBitmap := TBitmap.Create();
aBitmap.Handle := aTempBitmap;
...
aBitmap ausgeben auf Formular ---> zeigt nur Bitmap ohne Inhalt

semo 20. Mai 2006 21:16

Re: PSafeArray nach Bitmap
 
hier einmal nen bissl mehr code:

Delphi-Quellcode:
var
  aTempBitmap : HBITMAP;
  aOleVariant : OleVariant;
  iMin, iMax : Integer;
  Val        : pSafeArray;
  pBitmap    : Pointer;
begin
  // Infos loggen:
  WriteToLogFile(Format('aIproImage.Info.Width       = %d', [aIproImage.Info.Width]));
  WriteToLogFile(Format('aIproImage.Info.Height      = %d', [aIproImage.Info.Height]));
  WriteToLogFile(Format('aIproImage.Info.DPIX        = %d', [aIproImage.Info.DPIX]));
  WriteToLogFile(Format('aIproImage.Info.DPIY        = %d', [aIproImage.Info.DPIY]));
  WriteToLogFile(Format('aIproImage.Info.BytesPerLine = %d', [aIproImage.Info.BytesPerLine]));
  WriteToLogFile(Format('aIproImage.Info.BitsPerPixel = %d', [aIproImage.Info.BitsPerPixel]));

  // Bilddaten in ein OleVariant laden
  aOleVariant := aIproImage.Get( aIproImage.Info,
                                 0,
                                 0,
                                 0,
                                 0,
                                 aIproImage.Info.Width,
                                 aIproImage.Info.Height);

  Val := PSafeArray(TVariantArg(aOleVariant).ppArray);

  WriteToLogFile(Format('ElementSize = %d', [Val.cbElements]));
  ActiveX.SafeArrayGetLBound(Val, 1, iMin);
  ActiveX.SafeArrayGetUBound(Val, 1, iMax);
  WriteToLogFile(Format('iMin=%d', [iMin]));
  WriteToLogFile(Format('iMax=%d', [iMax]));

  SafeArrayAccessData(Val, pBitmap);

  // PixelFormat setzen:
  case aIproImage.Info.BitsPerPixel of
    ITYPE_BW       : aBitmap.PixelFormat := pf1bit;
    ITYPE_GRAY4     : aBitmap.PixelFormat := pf4bit;
    ITYPE_8BIT     : aBitmap.PixelFormat := pf8bit;
    ITYPE_TRUECOLOR : aBitmap.PixelFormat := pf24bit;
  end;

  aTempBitmap := CreateBitmap( aIproImage.Info.Width,
                               aIproImage.Info.Height,
                               1,
                               aIproImage.Info.BitsPerPixel,
                               pBitmap);

  WriteToLogFile(Format('aTempBitmap (Typ Handle)=%d', [aTempBitmap]));

  aBitmap.Width := const_ImageWidth;
  aBitmap.Height := const_ImageHeight;

  aBitmap.Handle := aTempBitmap;

  SafeArrayUnaccessData(Val);


Alle Zeitangaben in WEZ +1. Es ist jetzt 10:12 Uhr.

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