logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
carrot  
#1 Posted : Monday, January 21, 2019 4:12:44 AM(UTC)
carrot

Rank: Newbie

Groups: Registered
Joined: 12/4/2017(UTC)
Posts: 9
Slovakia
Location: Bratislava

Hello,

I have an issue with disposing PdfBitmap.

It seems to disposing PdfBitmap corrupt memory. On the last line app throws System.AccessViolationException: 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'.
When I remove pdfBitmap dispose (avoiding using), it works.
I'm using 3.11.3.2704 version, but I tried it also on newest version.

Code:
using (var pdfBitmap = new PdfBitmap(width, height, true))
{
	pdfBitmap.FillRect(0, 0, width, height, Color.White);
	this.pdfPage.Render(pdfBitmap, 0, 0, width, height, PageRotate.Normal, RenderFlags.FPDF_LCD_TEXT);

	Bitmap = (Bitmap)pdfBitmap.Image.Clone();
}

// this throws System.AccessViolationException
Bitmap.Save(@"D:\test.jpeg", System.Drawing.Imaging.ImageFormat.Jpeg);


Can you help me with it?

Thank you
Paul Rayman  
#2 Posted : Monday, January 21, 2019 5:20:09 AM(UTC)
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 779

Thanks: 1 times
Was thanked: 97 time(s) in 95 post(s)
Hi,

Please use

Code:

Bitmap = new Bitmap(pdfBitmap.Image);


instead of Clone().

The System.Drawing.Image.Clone() method creates a new Bitmap object but the pixel data is shared with the original bitmap object. The Bitmap(Image) constructor also creates a new Bitmap object but one that has its own copy of the pixel data.

More details can be found here:
https://stackoverflow.co...one-and-new-bitmapbitmap

carrot  
#3 Posted : Monday, January 21, 2019 5:47:37 AM(UTC)
carrot

Rank: Newbie

Groups: Registered
Joined: 12/4/2017(UTC)
Posts: 9
Slovakia
Location: Bratislava

Super, it works.
Thank you.
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.