Images from memory - bad quality

Some time ago I communicated with you concerning images from memory to pdf. The images are poor quality and Tommy Wang responded that the problem will be fixed in a future version.

When can I expect the problem to be resolved?

Thanks in advance

David

Hi David,

We have added this task in our plan. I hope it can be finished late this month or early next month. Is it possible for you to use image file as work around?

No, unfortunately using temporary imagefiles is not an option that we wish to implement. We have potentially several thousand users so we do not want more temporary file creations than necessary. We must wait for your next version.

OK. We will support this ASAP.

This feature is now supported in the hotfix 2.9.2.

I am not quite sure how to use the new property ImageInfo.ImageStream. Can you please help me to adjust my present code?

...

//Read into PDF from memory

MemoryStream mstream = new MemoryStream();

pic.Save(mstream, ImageFormat.Gif);

Image pdfImage = new Image();

pdfImage.ImageInfo.ImageFileType = ImageFileType.MemoryBmp;

pdfImage.ImageInfo.OpenType = ImageOpenType.Memory;

BinaryReader reader = new BinaryReader(mstream);

mstream.Position = 0;

pdfImage.ImageInfo.MemoryData = reader.ReadBytes((int) mstream.Length);

Section sec1 = pdf.Sections.Add();

sec1.Paragraphs.Add(pdfImage);

...

Thanks for considering Aspose.

Please refer to the API document about ImageSteam usage.

lmage.ImageStream

Your example uses file from disc, but I need to use file from memory. I can not get it to work.

Please consider my code from the previous post and tell me what I am doing wrong.

The ImageInfo.ImageStream supports both file stream and memory stream. Here is a complete example:

Chart chart = new Chart();
chart.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

Series s = new Series();
s.ChartType = ChartType.Bar;
s.DataPoints.Add(new DataPoint(2, -2));
s.DataPoints.Add(new DataPoint(4, 7));
s.DataPoints.Add(new DataPoint(6, -9));
chart.SeriesCollection.Add(s);

System.IO.MemoryStream mstream = new System.IO.MemoryStream();
chart.Save(mstream,System.Drawing.Imaging.ImageFormat.Png);

Pdf pdf = new Pdf();

Section sec = pdf.Sections.Add();

Image img = new Image();
img.ImageInfo.ImageFileType = ImageFileType.Png;
img.ImageInfo.ImageStream = mstream;

sec.Paragraphs.Add(img);

pdf.Save("d:/test/test.pdf");

Considering my previously posted code, I changed it to the code below and thereby the way the stream is read. I get an error when opening the pdf document - the error is enclosed as error.jpg.

*************************************

MemoryStream mstream = new System.IO.MemoryStream();

pic.Save(mstream, ImageFormat.Gif);

Image pdfImage = new Image();

pdfImage.ImageInfo.ImageFileType = ImageFileType.Gif;

pdfImage.ImageInfo.ImageStream = mstream;

Section sec1 = pdf.Sections.Add();

sec1.Paragraphs.Add(pdfImage);

*********************************

If I save the image to disc first and then reads it into a FileStream, it works but that is unfortunately not an option for us.

I have not found any error in your code. This might be a bug. Can you please provide a runable example that can reproduce this error?

We've discovered a caching problem, which caused the code not to work properly.

It works just fine now. Thanks for your help and sorry for the inconvenience.