How to make memorystream in Aspose.Imaging?

Thank you for your service.

I bought Aspose license. Now I try to convert files to memory stream except input file and out file.
Currently, I converted tiff to bmp and then inputed bmp(through my Done function) and then converted bmp to tiff
Also Input file is tidone.tiff and output file is tidone_bmp.tiff . Tiff has 3page image file.
I tried to read Aspose.Imaging reference but I didn’t look for making memorystream in the middle of files.
Could you please tell me how to make memorystream?

TiffImage multiImage = (TiffImage)Aspose.Imaging.Image.Load(“tidone.tiff”); // ***at fist input file : tidone.tiff
int frameCounter = 0;
foreach (TiffFrame tiFrame in multiImage.Frames)
{
multiImage.ActiveFrame = tiFrame;
Aspose.Imaging.Color[] PO = multiImage.LoadPixels(tiFrame.Bounds);
BmpOptions bmpCreateOptions = new BmpOptions();
string f = String.Format("{0:D2}", frameCounter);
bmpCreateOptions.Source = new FileCreateSource(string.Format("{0}\{1}tiff{2}_out.bmp", datadir, tidone, f), false);
using (BmpImage bmpImage = (BmpImage)Aspose.Imaging.Image.Create(bmpCreateOptions, tiFrame.Width, tiFrame.Height))
{
bmpImage.SavePixels(tiFrame.Bounds, PO);
bmpImage.Save();
}
frameCounter++;
}
foreach (string f in Directory.GetFiles("\", "
_out.bmp"))
{
filename = (Path.GetFileNameWithoutExtension(f));
StringBuilder file = new StringBuilder(f);
StringBuilder fout = new StringBuilder("\" + filename + “_out2” + “.bmp”);
Done(file, fout);
// I made ’ Done Function’ (file: input file), fout(: out file)
}

         TiffOptions outings = new TiffOptions(TiffExpectedFormat.TiffCcittFax3);               

outings.Source = new Aspose.Imaging.Sources.StreamSource(new MemoryStream());
using (TiffImage tiffI = (TiffImage)Aspose.Imaging.Image.Create(outings, newWidth, newHeight))
{
int index = 0;
foreach (var file in Directory.GetFiles("\", “*_out2.bmp”))
{
using (RasterImage RIT = (RasterImage)Aspose.Imaging.Image.Load(file))
{
RIT.Resize(newWidth, newHeight, ResizeType.NearestNeighbourResample);
TiffFrame frame = tiffI.ActiveFrame;
frame = new TiffFrame(new TiffOptions(outings), newWidth, newHeight);
frame.SavePixels(frame.Bounds, RIT.LoadPixels(RIT.Bounds));
tiffI.AddFrame(frame);
index++;
}
}
tiffI.Save("\" + “tidone_bmp.tiff”); //Last out file : tidone_bmp.tiff
}

@YoungLEE,

I have tried to under the requirements shared by you and have not been able to under your following question.

Can you please share what you ought to require from Aspose.Imaging to offer you in your scenario. If you want to save BMP image or TIFF image to stream, that is allowed in Aspose.Image as it provide Save method overload to save image as streams.

Many Thanks,

Mudassir Fayyaz

Thank you for your answer.

Could you please tell me how to make memorystream? It means to know me how to change the source I created as a memory stream instead of file. This description can be found in the attached file. convert File to memorystream.png (37.8 KB)
I would like to keep input file at first and out file last. But In the middle of files
, I would like to convert the source as files to the source as a memorystream.
If you think you could convert the source I created to memorystream type, Could you please help me where to modify?

The sources are:

            TiffImage multiImage = (TiffImage)Aspose.Imaging.Image.Load("a.tiff");                            
                int frameCounter = 0;

                foreach (TiffFrame tiffFrame in multiImage.Frames)
                {
                    multiImage.ActiveFrame = tiffFrame;
                    Aspose.Imaging.Color[] pixels = multiImage.LoadPixels(tiffFrame.Bounds);
           
                    BmpOptions bmpCreateOptions = new BmpOptions();                       
                    string f = String.Format("{0:D2}", frameCounter);                      
                    bmpCreateOptions.Source = new FileCreateSource(string.Format("\\{0}_tiff_{1}_out.bmp", a, f), false);

                    using (BmpImage bmpImage = (BmpImage)Aspose.Imaging.Image.Create(bmpCreateOptions, tiffFrame.Width, tiffFrame.Height))
                    {                          
                        bmpImage.SavePixels(tiffFrame.Bounds, pixels);
                        bmpImage.Save();
                    }
                    frameCounter++;
                }

            foreach (string f in Directory.GetFiles("\\", "*_out.bmp"))
            {
                strFileName = (Path.GetFileNameWithoutExtension(f));
                StringBuilder inputfile = new StringBuilder(f);                                               
                StringBuilder outfile = new StringBuilder( "\\" + strFileName + "_outt" + ".bmp");

                DoneFex(inputfile, outfile); 
            }
     
            TiffOptions outputSettings = new TiffOptions(TiffExpectedFormat.TiffLzwRgb);              
            outputSettings.Source = new Aspose.Imaging.Sources.StreamSource(new MemoryStream());
               
            using (TiffImage tiffImage = (TiffImage)Aspose.Imaging.Image.Create(outputSettings, newWidth, newHeight))
            {                   
                int index = 0;               
                foreach (var file in Directory.GetFiles(tempPath2 + "\\", "*_outt.bmp"))
                {
                    using (RasterImage ri = (RasterImage)Aspose.Imaging.Image.Load(file))
                    {
                        ri.Resize(newWidth, newHeight, ResizeType.NearestNeighbourResample);
                        TiffFrame frame = tiffImage.ActiveFrame;
                        if (index > 0)
                        {                             
                            frame = new TiffFrame(new TiffOptions(outputSettings), newWidth, newHeight);                                                                       
                        }                      
                        frame.SavePixels(frame.Bounds, ri.LoadPixels(ri.Bounds));

                        if (index > 0)
                        {                      
                            tiffImage.AddFrame(frame);
                        }
                                index++;                               <a class="attachment" href="/uploads/default/2901">convert File to memorystream.png</a> (37.8 KB)

					}
                    tiffImage.Save("\\"+ "a_outiff.tiff");
                }
			}

@YoungLEE,

I have observed your sample code and unable to use that owing to some custom function calls in that. However, I suggest you to please try adding following alternate in your code.

MemoryStream Stream = new MemoryStream();
bmpImage.Save(Stream);
Stream.Position = 0;

Many Thanks,

Mudassir Fayyaz

Thank you for your response.

Could you tell me where some custom function is? Also, In my code , Could you tell me where to add your code ?Could you please tell me my question in detail ? I bought Aspose license. I would like to do my project well.

Thanks

YoungLEE

@YoungLEE,

I have found following function call in your code for which there exists no definition. Moreover, there are some string and other variables that are not defined.

I have still modified the sample code where I am saving the tiff frames to collection of bitmap streams and then loading the individual streams from collection. Please try using the shared sample code on your end with modification as per your application. if there is still an issue then please provide the working sample Visual Studio project with us.

    public static void TiffToPNG()
    {
          TiffImage multiImage = (TiffImage)Aspose.Imaging.Image.Load("a.tiff");                            
            int frameCounter = 0;

            List<MemoryStream> StreamCollection = new List<MemoryStream>();

            foreach (TiffFrame tiffFrame in multiImage.Frames)
            {
                multiImage.ActiveFrame = tiffFrame;
                Aspose.Imaging.Color[] pixels = multiImage.LoadPixels(tiffFrame.Bounds);
       
                BmpOptions bmpCreateOptions = new BmpOptions();                       
                string f = String.Format("{0:D2}", frameCounter);                      
             //   bmpCreateOptions.Source = new FileCreateSource(string.Format("\\{0}_tiff_{1}_out.bmp", a, f), false);
                 MemoryStream Stream=new MemoryStream();
                using (BmpImage bmpImage = (BmpImage)Aspose.Imaging.Image.Create(bmpCreateOptions, tiffFrame.Width, tiffFrame.Height))
                {
                    Stream = new MemoryStream();                       
                    bmpImage.SavePixels(tiffFrame.Bounds, pixels);
                    bmpImage.Save();

                    bmpImage.Save(Stream);
                    Stream.Position = 0;
                    StreamCollection.Add(Stream);
                }
                frameCounter++;
            }
        /*
        foreach (string f in Directory.GetFiles("\\", "*_out.bmp"))
        {
            strFileName = (Path.GetFileNameWithoutExtension(f));
            StringBuilder inputfile = new StringBuilder(f);                                               
            StringBuilder outfile = new StringBuilder( "\\" + strFileName + "_outt" + ".bmp");

            DoneFex(inputfile, outfile); 
        }
 */
        TiffOptions outputSettings = new TiffOptions(TiffExpectedFormat.TiffLzwRgb);              
        outputSettings.Source = new Aspose.Imaging.Sources.StreamSource(new MemoryStream());
           
        using (TiffImage tiffImage = (TiffImage)Aspose.Imaging.Image.Create(outputSettings, newWidth, newHeight))
        {                   
            int index = 0;               
           // foreach (var file in Directory.GetFiles(tempPath2 + "\\", "*_outt.bmp"))
            foreach (var stream in StreamCollection)
            {
                using (RasterImage ri = (RasterImage)Aspose.Imaging.Image.Load(stream))
                {
                    ri.Resize(newWidth, newHeight, ResizeType.NearestNeighbourResample);
                    TiffFrame frame = tiffImage.ActiveFrame;
                    if (index > 0)
                    {                             
                        frame = new TiffFrame(new TiffOptions(outputSettings), newWidth, newHeight);                                                                       
                    }                      
                    frame.SavePixels(frame.Bounds, ri.LoadPixels(ri.Bounds));

                    if (index > 0)
                    {                      
                        tiffImage.AddFrame(frame);
                    }
                            index++;                  
				}
                tiffImage.Save("\\"+ "a_outiff.tiff");
            }
		}
    }

Many Thanks,

Mudassir Fayyaz

Dear mudassir.fayyaz

Thank you so much for your answer. Also, I am so sorry for the late response.
I am working hard for succeeding my project which converting files to the memorystream.
I tried to do it after I looked your answer. I got it. Thank you so much. Also, I discovered my mistakes.
My mistakes are custom functions which I made. I am so sorry but thank you so much.

Best Regards.
YoungLEE

@YoungLEE,

You are always welcome. Please share with us if we may help you in addressing issues incurring on your end.

Many Thanks,

Mudassir Fayyaz