AVIReader - taking too long to save frames

I am developing a program to grab images from four cameras and turn them into one picture only in style quad, 4 images in one. And it generate a .avi

        AVIReader reader = new AVIReader();
        List<byte[]> ImagemMainb = new List<byte[]>();
        reader.Open(_rootPath + Path.GetFileName(_arqsCam01[i]));
        while (reader.Position - reader.Start < reader.Length)
            {
                Bitmap aux = reader.GetNextFrame();
                Bitmap r = new Bitmap(aux.Width * 2, aux.Height * 2, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                using (var g = Graphics.FromImage(r))
                {
                    g.DrawImage(aux, new Rectangle(0, 0, aux.Width, aux.Height));
                    ImagemMainb.Add(ImageToByte(r));                                                             
                 }                                    
            }
            reader.Close();
            reader.Dispose();

And here is the method ImageToByte

public static byte[] ImageToByte(Image img)
    {
        byte[] byteArray = new byte[0];
        using (MemoryStream stream = new MemoryStream())
        {
            img.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
            stream.Close();

            byteArray = stream.ToArray();
        }
        return byteArray;
    }

Using these codes takes too long to finish the process! When I have a list of 84000 bitmaps in that case are 280 videos with frame rate = 5, size = 320x240, it takes forever. Would have any problem in this code or have a better way?

Answers


i found the answer.

 AVIReader reader = new AVIReader();
 List<Bitmap> ImagemMain = new List<byte[]>();
 reader.Open(_rootPath + Path.GetFileName(_arqs[0]));
 while (reader.Position - reader.Start < reader.Length)
 {
        using (var aux = reader.GetNextFrame())
        {
             using (var r = new Bitmap(640, 480))
             {
                   using (var g = Graphics.FromImage(r))
                   {                                               
                       g.DrawImage(aux, new Rectangle(0, 0, aux.Width, aux.Height));                                                   
                       ImagemMain.Add((Bitmap)r.Clone());
                   }

             }
         }
  }

Every video uploaded AVIWriter I open the file .avi and add bitmap. With this is much more fast and does not take up almost no memory.


Need Your Help

Android Webview, working with Anchors

java android anchor android-webview

I am loading a webpage into a webview from the database with the loadDataWithBaseURL() function and am trying to subsequently jump to an Anchor point. When I place a button just below the webview ...

get keydown on application/form load in vb.net

.net vb.net keyboard application-start

I want to able to hold a key down while the application is loading and depending on which is being held down a certain form is shown.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.