Autor Beitrag
relapse
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 50



BeitragVerfasst: Mo 09.07.12 17:38 
Hallo! Ich versuche eine PDF-Datei in ein Bitmap zu exportieren. Dafür steht mir eine Bibliothek zur Verfügung. Beim Ausführen einer Funktion aus diesem Bibliothek bekomme ich keinen Fehler, das Bitmap, das ich am Ende in eine .bmp-Datei speichere, hat zwar Größe von Paar MB ist aber komplett schwarz. Ich vermute, dass entweder das Bitmap oder DeviceContext (wird von der Funktion der erwähnten Bibliothek benötigt) nicht richtig initialisiert werden. Kann mir vielleicht jemand sagen, ob ich sie richtig initialisiere? Danke!

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
var bitmap = new Bitmap(aktuelleBreite, aktuelleHoehe);      
var graphics = Graphics.FromImage(bitmap);
var deviceContext = graphics.GetHdc();
var parameters  = new Bibliothek.Parameters { ... }; // wird alles initialisiert.
//var pageRect = new Bibliothek.RECT { top = 0, left = 0, right = aktuelleBreite, bottom = aktuelleHoehe }; // auch so ausprobiert.
var pageRect = new Bibliothek.RECT { top = aktuelleHoehe, left = aktuelleBreite, right = 0, bottom = 0 };
var rect = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(Bibliothek.RECT)));
Marshal.StructureToPtr(pageRect, rect, false);
Bibliothek.FunktionPdfExport(handle, aktuelleSeite, deviceContext, ref parameters); // handle habe ich, hier kein Fehler!!!
bitmap.Save(@"C:\bild.bmp", ImageFormat.Bmp);


Zuletzt bearbeitet von relapse am Di 10.07.12 08:21, insgesamt 1-mal bearbeitet
jfheins
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 918
Erhaltene Danke: 158

Win 10
VS 2013, VS2015
BeitragVerfasst: Mo 09.07.12 19:03 
Hi,
in der Doku steht:
Zitat:
Calls to the GetHdc and ReleaseHdc methods must appear in pairs.


Probier' mal folgendes:
ausblenden C#-Quelltext
1:
2:
3:
4:
[...]
Bibliothek.FunktionPdfExport(handle, aktuelleSeite, deviceContext, ref parameters); // handle habe ich, hier kein Fehler!!!
graphics.ReleaseHdc(deviceContext); // Neu
bitmap.Save(@"C:\bild.bmp", ImageFormat.Bmp);
relapse Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 50



BeitragVerfasst: Di 10.07.12 08:29 
Ne, hat leider nicht geholfen :(
relapse Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 50



BeitragVerfasst: Di 10.07.12 12:50 
Ich hab's!

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
var bitmap = new Bitmap(aktuelleBreite, aktuelleHoehe);      
var graphics = Graphics.FromImage(bitmap);

graphics.Clear(Color.White); // das... (sonst ist alles dunkel)

var deviceContext = graphics.GetHdc();
var parameters  = new Bibliothek.Parameters { ... };

var pageRect = new Bibliothek.RECT { top = 0, left = 0, right = aktuelleBreite, bottom = aktuelleHoehe }; // und das (sorry, hab's doch nicht ausprobiert, S. meine erste Meldung im Thread)!

var rect = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(Bibliothek.RECT)));
Marshal.StructureToPtr(pageRect, rect, false);
Bibliothek.FunktionPdfExport(handle, aktuelleSeite, deviceContext, ref parameters);
graphics.ReleaseHdc(deviceContext); // Danke für den Hinweis (S. die erste Antwort)!
bitmap.Save(@"C:\bild.bmp", ImageFormat.Bmp);


Jetzt habe ich statt schöner PDF-Vektorgrafik eckige Bitmap! :shock: