ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Save Bitmap to PNG
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

jenswahl

Germany
74 Posts

Posted - Feb 26 2018 :  08:30:04  Show Profile  Reply
Hello,

I get a Bitmap from a PDF-page and can it save without ImageEn as Bitmap in a good result. Using ImageEnView (to save it in another format) brings partial error-images:


//This works fine:
//(The result of PdfView1.RenderPage is a Bitmap, created from the displayed PDF-page)

procedure SaveToBitmap;
var
	Bitmap:									TBitmap;
	
begin
	Bitmap := PdfView1.RenderPage(0, 0, PdfView1.Width, PdfView1.Height, ro0, PdfView1.Options);
	//allow only bmp-Filter:
	if SaveImageEnDialog1.Execute then begin
		try
			Bitmap.SaveToFile(SaveImageEnDialog1.FileName);
		finally
			Bitmap.Free;
		end;
	end;
end;


This ends in a B/W-image on saving as PNG- or BMP-File; Jpg is OK:

procedure SaveBitmap(Sender: TObject);
var
	sExt:									String;

begin
	//ievPDF is TImageEnView; LegacyBitmap has no influence
	ievPDF.Bitmap.Assign(PdfView1.RenderPage(0, 0, PdfView1.Width, PdfView1.Height, ro0, PdfView1.Options));
	//here looks still OK:
	ievPDF.Update;
	if SaveImageEnDialog1.Execute then begin
//nothing:
//		sExt := Lowercase(ExtractFileExt(SaveImageEnDialog1.FileName));
//		if (sExt = '.png') then begin
//			ievPDF.IO.Params.PNG_Filter := ioPNG_FILTER_ALL; 	//ioPNG_FILTER_NONE; 	// ioPNG_FILTER_PAETH;
//			ievPDF.IO.Params.PNG_Compression := 5;
//		end;
		try
//nothing			ievPDF.RemoveAlphaChannel;
			ievPDF.IO.SaveToFile(SaveImageEnDialog1.FileName);
		finally
			ievPDF.Blank;
		end;
	end;
end;


What is the reason for it? I'm using IE 7.5.0.

Kind regards,
Jens

xequte

39061 Posts

Posted - Feb 26 2018 :  14:36:42  Show Profile  Reply
Hi

You should not use TImageEnView.Bitmap, rather use TImageEnView.IEBitmap.

Does it work with:
ievPDF.LegacyBitmap := False;
ievPDF.IEBitmap.Assign(PdfView1.RenderPage(0, 0, PdfView1.Width, PdfView1.Height, ro0, PdfView1.Options));

If the colors are not right, check the value of ievPDF.IEBitmap.PixekFormat, and relevant format properties, such as TIFF_Compression:

https://www.imageen.com/help/TIOParams.html



Nigel
Xequte Software
www.imageen.com
Go to Top of Page

jenswahl

Germany
74 Posts

Posted - Feb 27 2018 :  02:31:31  Show Profile  Reply
Thank you for the suggestions but nothing solved the problem. The Params, Pixelformat and Bitcount seemed to be OK. But I got no Preview for Bmp or Png on SaveImageEnDialog - only for B/W-images. I believe that the rendered PDF page is a corrupted Bmp.

So I'm using a workaround: Create a Bitmap from the rendered PDF page and save it to a temporarily file. Than load it using ImageEnView and I can save in all formats without a problem.

Jens
Go to Top of Page

xequte

39061 Posts

Posted - Feb 27 2018 :  13:40:36  Show Profile  Reply
Hi Jens

Even if you assign the temporary bitmap to the TIEBitmap it fails?

You could also save/load from a stream rather than a temp file...

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

jenswahl

Germany
74 Posts

Posted - Feb 28 2018 :  01:42:10  Show Profile  Reply
Hello Nigel,

yes, I tried a lot of variants, also the following:


Bitmap := PdfView1.RenderPage(0, 0, PdfView1.Width, PdfView1.Height, ro0, PdfView1.Options);
ievPDF.Bitmap.Assign(Bitmap);
//also ievPDF.IEBitmap.Assign(Bitmap);


Every time the same result: Jpg OK, Png and Bmp are only B/W-images with a raster. Different settings with IOParams: The same result.
What I saw: in the SaveImageEnDialog the preview is only available for B/W (Bitmap and Png) and only for the result, not for the source image. If I want to save as Jpg I have a (colored) preview also for 16M (for instance), see the attached images.

The idea with the stream is good, I will try it. Thank you.

Jens










Go to Top of Page

jenswahl

Germany
74 Posts

Posted - Feb 28 2018 :  02:43:18  Show Profile  Reply
Hello Nigel,

the SaveToStream/LoadFromStream ends with a gray Png- or Jpg-file, you can not see any text or image. So I believe that the streamed bitmap is corrupt.
Thank you for your help. I will keep the version to save the bitmap to a file and load it to ImageEnView. This works.

Jens
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: