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

New Post: Create a grayscale png image from a byte buffer

$
0
0
here is a way to do it a bit better:
        //convert raw buffer to grayscale 8 bits png image
        static void SaveGrayscale8bitsPngImage(byte[] pixels, string path)
        {
            MagickReadSettings settings = new MagickReadSettings();
            settings.Width = 640;
            settings.Height = 480;
            settings.PixelStorage = new PixelStorageSettings(StorageType.Char, "R");

            MagickImage imageTmp = new MagickImage(pixels, settings);

            MagickImage image = imageTmp.Separate(Channels.Red).First();
            image.Format = MagickFormat.Png;
            image.SetDefine(MagickFormat.Png, "color-type", "0"); //0 = grayscale image 
            image.SetDefine(MagickFormat.Png, "bit-depth", "8"); //number of bits per index
            image.SetDefine(MagickFormat.Png, "compression-level", "9"); //valid values are 0 through 9, with 0 providing the least but fastest compression and 9 usually providing the best and always the slowest.
            image.Write(path);
        }

Viewing all articles
Browse latest Browse all 3693

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>