Hello
When trying to convert a jpg file from memory stream I get an error when trying to save the file to tiff format with the following error:
"An attempt was made to move the position before the beginning of the stream."
Stack trace: " at Aspose.Imaging.Image.Save(Stream stream, ImageOptionsBase optionsBase)
at Aspose.Imaging.Image.Save(String filePath, ImageOptionsBase options)"
Here is my code:
MemoryStream memstream = new MemoryStream(filestream); // filestream is a byte array.
Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(memstream);
Aspose.Imaging.ImageOptions.TiffOptions options = new Aspose.Imaging.ImageOptions.TiffOptions();
options.Compression = Aspose.Imaging.FileFormats.Tiff.Enums.TiffCompressions.CcittRle;
image.Save(basedir + outputDir + filename + “.tif”, options);
Hope you can help.
Hi Robert,
Thank you for contacting Aspose support.
We have evaluated your presented scenario with the following piece of code and the latest version of
Aspose.Imaging for .NET 2.3.1. Unfortunately, we are unable to experience any problem on our end.
C#
byte[] stream = System.IO.File.ReadAllBytes(myDir + “sample.jpg”);
MemoryStream memstream =
new MemoryStream(stream);
// filestream is a byte array.
Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(memstream);
Aspose.Imaging.ImageOptions.TiffOptions options =
new Aspose.Imaging.ImageOptions.TiffOptions();
options.Compression = Aspose.Imaging.FileFormats.Tiff.Enums.TiffCompressions.CcittRle;
image.Save(myDir + “output.tif”, options);
In order to troubleshoot the problem further, we would request you to please download and use the latest assemblies (link shared above). In case the problem persists, please provide us your complete code (most preferably an executable sample application) and your input image for our review.
Hello again
I replaced the DLLs with version 2.3.1 as you suggested but unfortunately the problem persists. I have now tried two images. The first image is jpeg picture of a signed document I get the error I reported previously and is attached.
"An attempt was made to move the position before the beginning of the stream."
Stack trace: " at Aspose.Imaging.Image.Save(Stream stream, ImageOptionsBase optionsBase)
at Aspose.Imaging.Image.Save(String filePath, ImageOptionsBase options)"
When I use the other image it is converted, however, but the output image is a tiff image with only two colors, black and white. The input and output file is attached (koala pics).
The code snippet now is now:
MemoryStream memstream = new MemoryStream(filestream);
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(memstream))
{
Aspose.Imaging.ImageOptions.TiffOptions options = new Aspose.Imaging.ImageOptions.TiffOptions();
options.Compression = Aspose.Imaging.FileFormats.Tiff.Enums.TiffCompressions.None;
image.Save(basedir + outputDir + filename + “.tif”, options);
}
The complete code file is attached (I can not send you the whole project unfortunately).
I hope you can help.
Hi Robert,
Thank you for providing the sample images.
We are able to replicate the exception with message “An attempt was made to move the position before the beginning of the stream.” while converting your provided sample image with latest version of Aspose.Imaging for .NET 2.3.1. For the sake of investigation & correction, the problem has been logged in our bug tracking system under Ticket Id IMAGING-34111. Please note, other samples (Jpeg images) do not exhibit similar behavior therefore we suspect the problem could be sample specific. We will keep you posted with our investigation outcome.
Regarding your other inquiry, if you wish to maintain the colors while converting the Jpeg image to Tiff format, you have to specify few extra parameters for the object of TiffOptions class. Please have a look at below provided code snippet,
C#
byte[] stream = System.IO.File.ReadAllBytes(myDir + “koala.jpg”);
MemoryStream memstream =
new MemoryStream(stream);
Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(memstream);
Aspose.Imaging.ImageOptions.TiffOptions options =
new Aspose.Imaging.ImageOptions.TiffOptions();
options.Compression = Aspose.Imaging.FileFormats.Tiff.Enums.TiffCompressions.Lzw;
options.Photometric = TiffPhotometrics.Rgb;
options.BitsPerSample = new ushort[] { 8, 8, 8, };
image.Save(myDir + “output.tif”, options);
In above code snippet we have set the Photometric & BitsPerSample properties, and changed the compression method to LZW. Please check the following article for better elaboration of these properties.
Please feel free to write back in case you have further questions for us.
Hi Robert,
Thank you for the confirmation.
I have checked the ticket details that was logged earlier as IMAGING-34111. The ticket is currently in analysis phase so we may not be able to share more details, although we have concluded that the sample’s compression configuration slightly differs from whats prescribed by JFIF compression standards. We are looking into this matter further to provide the fix with upcoming release of Aspose.Imaging for .NET 2.4.0.
We will keep you posted with updates in this regard.
The issues you have found earlier (filed as IMAGING-34111) have been fixed in this update.
This message was posted using Notification2Forum from Downloads module by Aspose Notifier.
The issues you have found earlier (filed as ) have been fixed in this Aspose.Words for JasperReports 18.3 update.