How to use Bitmap object in Imaging from GetThumbnail Function without saving

Hello,

I am trying to create a multi-page single TIFF from a powerpoint document.

I use this function to get one bitmap from powerpoint slide (by using Aspose.Slides)

var bitmap = slides[i].GetThumbnail(options);

but I want to use this bitmap for TiffImage and TiffFrame in Aspose.Imaging

firstly I take bitmap into a memorystream and then when i tried to call this function
Image.Load(ms);  (by using Aspose.Imaging)

I got an exception
{“Cannot open an image. The image file format may be not supported at the moment.”}
"   at Aspose.Imaging.Image.\u0002(StreamContainer \u0002, LoadOptions \u0003)\r\n   at Aspose.Imaging.Image.Load(Stream stream)\r\n   at Converter.Business.AsposeSdk.AsposeImageDoc.CreateThumbnailFromBitmaps(List`1 bitmaps)"
{Aspose.Imaging.Image (Aspose.Imaging.StreamContainer, Aspose.Imaging.LoadOptions)}

But If i save my bitmap as a file like png and after I take it into my memorystream (reading from directly file) then Image.Load function works

I have similar error in Aspose.Words. When something is in memorystream, it throws out the same exception.

Well my question is that how to use my bitmap (windows drawing) objects in Aspose.Imaging

without saving?

Hi Ertan,

Thank you for your inquiry.

You can use System.IO.Stream objects to load an existing Image file using Aspose.Imaging. Following is the code demonstration. For details, please visit the links:


CODE:

//Create an instance of FileStream
using(System.IO.FileStream stream = new System.IO.FileStream(@"sample.bmp",System.IO.FileMode.Open))
{
//Create an instance of Image class and load an existing file through FileStream object by calling Load method
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(stream))
{
//do some image processing.
}
}

Please try the above at your end. Feel free to contact us in case of any query or comments.

Thank you for your reply but i think there is a missunderstanding.


I am not talking about bmp file. I said a “bitmap” object that is given by getthumnail function. So I dont have any physical file for it and i dont want to save it also. I just want to use “bitmap” instance in code.
Hi Ertan,

Thank you for writing us back.

Please develop a sample .Net project demonstrating the issue that you are facing. We will evaluate it and our end and update you with the feedback via this forum thread. The sample .Net project will help us to investigate/reproduce the issue at our end.

Hey, Okay I prepared a project, you can find it as an attachment. and here is the sample code also



var stream = new MemoryStream(File.ReadAllBytes(@“Test.pptx”));
Aspose.Slides.Presentation presentation = new Aspose.Slides.Presentation(stream);
      <span style="color:blue;">var</span> bitmap= presentation.Slides[0].GetThumbnail(<span style="color:blue;">new</span> <span style="color:#2b91af;">Size</span>(160, 160));

      <span style="color:blue;">var</span> tmpStream = <span style="color:blue;">new</span> <span style="color:#2b91af;">MemoryStream</span>();


      bitmap.Save(tmpStream,<span style="color:#2b91af;">ImageFormat</span>.Tiff); <span style="color:green;">//doesnt mather png or tiff or.. in anycase exception is throw</span>
      <span style="color:green;">//when i save bitmap in a file and after, read from the file it works. but from the stream, not working</span>

      <span style="color:blue;">try</span>
      {
          Aspose.Imaging.<span style="color:#2b91af;">Image</span> image = Aspose.Imaging.<span style="color:#2b91af;">Image</span>.Load(tmpStream);
       
      }
      <span style="color:blue;">catch</span> (<span style="color:#2b91af;">Exception</span> ex)
      {

          <span style="color:#2b91af;">MessageBox</span>.Show(ex.Message + <span style="color:#2b91af;">Environment</span>.NewLine + ex.InnerException);
      }</pre></pre></div><div><br></div><div><b><br></b></div><div><b><br></b></div><div><b><br></b></div><div><b>My expectation is that the code must work. I DO NOT WANT TO SAVE "bitmap object" in a physical file, i want to use it as a stream object. (NOT FROM THE FILE)</b></div><div><br></div><div><br></div><div><br></div>
Hi Ertan,

Thank you for sharing sample & sorry for the delay.

This is to update you that we have investigated the issue at our end. Initial investigation shows that the issue persists. The issue has been logged into our system with ID IMAGINGNET-2182. All of the details have been shared with the product team. Our product team will further look into this issue and provide feedback. We will update with the feedback via this forum thread.

Hello,


Thank you for your reply. I actually solved the problem but i believe that is should not be in that way. I mean I do not call this function to solve problem. Because i use normally that way and now I have to call an extra function that is stream Seek.

so If i made my code like

var stream = new MemoryStream(File.ReadAllBytes(@“Test.pptx”));
Aspose.Slides.Presentation presentation = new Aspose.Slides.Presentation(stream);
      <span style="color: blue;">var</span> bitmap= presentation.Slides[0].GetThumbnail(<span style="color: blue;">new</span> <span style="color: rgb(43, 145, 175);">Size</span>(160, 160));

      <span style="color: blue;">var</span> tmpStream = <span style="color: blue;">new</span> <span style="color: rgb(43, 145, 175);">MemoryStream</span>();


      bitmap.Save(tmpStream,<span style="color: rgb(43, 145, 175);">ImageFormat</span>.Tiff); <span style="color: green;">//doesnt mather png or tiff or.. in anycase exception is throw</span>
      <span style="color: green;">//when i save bitmap in a file and after, read from the file it works. but from the stream, not working</span>


          tmpStream.Seek(0, SeekOrigin.Begin);
try
          {
Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(tmpStream);
      }
      <span style="color: blue;">catch</span> (<span style="color: rgb(43, 145, 175);">Exception</span> ex)
      {

          <span style="color: rgb(43, 145, 175);">MessageBox</span>.Show(ex.Message + <span style="color: rgb(43, 145, 175);">Environment</span>.NewLine + ex.InnerException);
      }</pre></div><div style="color: rgb(51, 51, 51); font-family: Arial, Helvetica; font-size: 13px; background-color: rgb(255, 255, 255);"><br></div></div><div style="color: rgb(51, 51, 51); font-family: Arial, Helvetica; font-size: 13px; background-color: rgb(255, 255, 255);"><br></div><div style="color: rgb(51, 51, 51); font-family: Arial, Helvetica; font-size: 13px; background-color: rgb(255, 255, 255);">it will work. I dont know why it occurs an exception, even it is needed  to seek index 0, you could do that in the load function, couldnt you?</div><div style="color: rgb(51, 51, 51); font-family: Arial, Helvetica; font-size: 13px; background-color: rgb(255, 255, 255);"><br></div><div style="color: rgb(51, 51, 51); font-family: Arial, Helvetica; font-size: 13px; background-color: rgb(255, 255, 255);"><br></div><div style="color: rgb(51, 51, 51); font-family: Arial, Helvetica; font-size: 13px; background-color: rgb(255, 255, 255);">When I always want to use a stream like that I have to call always this Seek method and when i sometimes forget, i have to find out the problem. (I am writing a complete wrapper for aspose modules in order to create thumbnails)</div>
Hi Ertan,

Thank you for update.

It is good to know that issue has been resolved. Thank you for sharing the resolution with us. The information has been forwarded to the product team. They will use this information while fixing the issue.

The issues you have found earlier (filed as ) have been fixed in this Aspose.Words for JasperReports 18.3 update.