AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren

PSafeArray nach Bitmap

Offene Frage von "semo"
Ein Thema von semo · begonnen am 20. Mai 2006 · letzter Beitrag vom 20. Mai 2006
Antwort Antwort
Benutzerbild von semo
semo

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

PSafeArray nach Bitmap

  Alt 20. Mai 2006, 21: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
Benutzerbild von Khabarakh
Khabarakh

Registriert seit: 18. Aug 2004
Ort: Brackenheim VS08 Pro
2.876 Beiträge
 
#2

Re: PSafeArray nach Bitmap

  Alt 20. Mai 2006, 21:59
Das ist aber ein komischer VB-Code .

Das Bitmap-Handle kannst du Delphi-Referenz durchsuchenTBitmap.Handle (wow ) zuweisen. Dann kannst du das Bitmap auf ein Image oderwasauchimmer zeichnen.
Sebastian
Moderator in der EE
  Mit Zitat antworten Zitat
Benutzerbild von semo
semo

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

Re: PSafeArray nach Bitmap

  Alt 20. Mai 2006, 22:02
okay ok ist c
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
  Mit Zitat antworten Zitat
Benutzerbild von semo
semo

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

Re: PSafeArray nach Bitmap

  Alt 20. Mai 2006, 22:16
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);
  Mit Zitat antworten Zitat
Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

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:05 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