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

Notification

Icon
Error

New Topic Post Reply
Options
Go to last post Go to first unread
peterb  
#1 Posted : Wednesday, January 20, 2016 10:45:55 AM(UTC)
Quote
peterb

Rank: Newbie

Groups: Registered
Joined: 1/20/2016(UTC)
Posts: 7

Previously I created png using ghostscript (pnggray argument), a 1679x2609 greyscale png - size is about 88 KB.
Using pdfium, how would I get something comparable in size?

right now it is coming out rgb and about 700-800 KB.




Paul Rayman  
#2 Posted : Thursday, January 21, 2016 5:40:03 AM(UTC)
Quote
Paul Rayman

Rank: Administration

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

Thanks: 10 times
Was thanked: 133 time(s) in 130 post(s)
You can render page with grayscale flag into 8bpp indexed bitmap.

Somthig like this:

Code:

using (var doc = PdfDocument.Load(@"document.pdf"))
{
	var page = doc.Pages[0];
	int width = (int)page.Width;
	int height = (int)page.Height;
	int stride = width + (4 - width % 4);
	IntPtr buffer = Marshal.AllocHGlobal(stride * height * 1);
	using (var bmp = new PdfBitmap(width, height, BitmapFormats.FXDIB_8bppRgb, buffer, stride))
	{
	        bmp.FillRect(0, 0, (int)width, (int)height, Color.White);
                page.Render(bmp, 0, 0, width, height, PageRotate.Normal, RenderFlags.FPDF_GRAYSCALE);
		bmp.Image.Save(@"document.png", ImageFormat.Png);
	}
}

Edited by user Wednesday, July 20, 2016 3:27:58 PM(UTC)  | Reason: Not specified

Quick Reply Show Quick Reply
Users browsing this topic
Guest
New Topic Post Reply
Forum Jump  
You can post new topics in this forum.
You can reply to topics in this forum.
You can delete your posts in this forum.
You can edit your posts in this forum.
You cannot create polls in this forum.
You can vote in polls in this forum.