BodyTetrisWrapper.Program.SaveJPG C# (CSharp) Method

SaveJPG() public static method

public static SaveJPG ( byte pixels, int w, int h, string Filename ) : int
pixels byte
w int
h int
Filename string
return int
        public static int SaveJPG(byte[] pixels, int w, int h, string Filename)
        {
            // Define the image palette
            BitmapPalette myPalette = BitmapPalettes.Halftone256;

            // Creates a new empty image with the pre-defined palette

            BitmapSource image = BitmapSource.Create(
                w,
                h,
                96,
                96,
                PixelFormats.Rgb24,
                myPalette,
                pixels,
                w * 3);

            FileStream stream = new FileStream(Filename, FileMode.Create);
            JpegBitmapEncoder encoder = new JpegBitmapEncoder();

            //encoder.Interlace = PngInterlaceOption.On;
            encoder.Frames.Add(BitmapFrame.Create(image));
            encoder.Save(stream);

            stream.Close();

            return 0;
        }