Thema: Delphi PSafeArray nach Bitmap

Einzelnen Beitrag anzeigen

Benutzerbild von semo
semo

Registriert seit: 24. Apr 2004
755 Beiträge
 
Delphi 2010 Professional
 
#1

PSafeArray nach Bitmap

  Alt 20. Mai 2006, 20:48
ich steh glaube im wald und seh die bäume nicht

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?
  Mit Zitat antworten Zitat