Quantcast
Channel: magick Discussions Rss Feed
Viewing all articles
Browse latest Browse all 3693

New Post: ToByteArray performance issue

$
0
0
Hi,

I have to convert bitmap to byte[] but compress rate when i use Encoder of .NET is not good.
I found Magick.NET with compress rate good!! Yeah!! Thanks dlemstra!
But performance of Magick.NET to convert MagickImage to bytes are high(about 300ms) . Encoder of .NET almost instantaneous (0-5ms)
Here is my test code:
byte[] bytes = null;
            MagickImage mImage = new MagickImage();

            Stopwatch total = new Stopwatch();
            Stopwatch read = new Stopwatch();
            Stopwatch toBytes = new Stopwatch();
            // Stopwatch resize = new Stopwatch();
            total.Start();
            for (int i = 0; i < 100; i++)
            {
                read.Start();
                // image is bitmap image object in memory
                mImage.Read(image);
                read.Stop();
                //resize.Start();
                //mImage.Resize(80);
                //resize.Stop();
                toBytes.Start();
                bytes = mImage.ToByteArray(MagickFormat.WebP);
                //mImage.Format = MagickFormat.WebP;
                //mImage.Write("image.webp");
                toBytes.Stop();
            }
            total.Stop();

            Console.WriteLine("Time: {0}, {1}", read.ElapsedMilliseconds, bytes.ElapsedMilliseconds);
The result:
Read: 6340
To byte array: 31159
Image resolution: 1366 * 768

Please tell me my code have some thing wrong? How to increase performance?
One again, thank U for written a useful lib

Viewing all articles
Browse latest Browse all 3693

Trending Articles