src/K4W.KinectVOD.Client.WPF/Processors/ImageProcessor.cs
/// <summary>
/// Save a buffer as a JPEG
/// </summary>
/// <param name="data">Image data</param>
/// <param name="width">Width of the image</param>
/// <param name="height">Height of the image</param>
/// <param name="stride">Stride of the image</param>
/// <param name="folder">Output folder</param>
/// <param name="filename">Filename</param>
Save a buffer as a JPEG
Save a buffer as a JPEG
public static async Task SaveJpegAsync(byte[] data, int width, int height, int stride, string folder, string filename)
        {
            Task saveJpegTask = Task.Run(() =>
            {
                if (data != null)
                {
                    WriteableBitmap bmp = new WriteableBitmap(width, height, 96.0, 96.0, PixelFormats.Bgr32, null);
                    bmp.WritePixels(new Int32Rect(0, 0, width, height), data, stride, 0);
                    JpegBitmapEncoder enc = new JpegBitmapEncoder();
                    enc.Frames.Add(BitmapFrame.Create(bmp));
                    string path = Path.Combine(folder, filename + ".jpg");
                    try
                    {
                        using (FileStream fs = new FileStream(path, FileMode.Create))
                        {
                            enc.Save(fs);
                        }
                    }
                    catch (IOException ex)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("Error! Exception - " + ex.Message);
                    }
                }
            });
            await saveJpegTask;
        }
public static async Task SaveJpegAsync ( byte [ ] data , int width , int height , int stride , string folder , string filename ) { Task saveJpegTask = Task . Run ( ( ) => { if ( data != null ) { WriteableBitmap bmp = new WriteableBitmap ( width , height , 96.0 , 96.0 , PixelFormats . Bgr32 , null ) ; bmp . WritePixels ( new Int32Rect ( 0 , 0 , width , height ) , data , stride , 0 ) ; JpegBitmapEncoder enc = new JpegBitmapEncoder ( ) ; enc . Frames . Add ( BitmapFrame . Create ( bmp ) ) ; string path = Path . Combine ( folder , filename + " " ) ; try { using ( FileStream fs = new FileStream ( path , FileMode . Create ) ) { enc . Save ( fs ) ; } } catch ( IOException ex ) { Console . ForegroundColor = ConsoleColor . Red ; Console . WriteLine ( " " + ex . Message ) ; } } } ) ; await saveJpegTask ; }
Save a buffer as a JPEG
Save a buffer as a JPEG
// Create a new bitmap // write pixels to bitmap // create jpg encoder from bitmap // create frame from the writable bitmap and add to encoder // Create whole path // write the new file to disk
data
byte[]
None
width
int
Width of the image
Width of the image
height
int
Height of the image
Height of the image
stride
int
Stride of the image
Stride of the image
folder
string
None
filename
string
None