programming-examples/c-sharp/Others/Write Jpeg file from BitmapSource.cs
2019-11-15 12:59:38 +01:00

26 lines
664 B
C#

Write Jpeg file from BitmapSource
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Media.Imaging;
using System.IO;
class UseBitmapCodecs
{
static void WriteJpeg(string fileName, int quality, BitmapSource bmp)
{
JpegBitmapEncoder encoder = new JpegBitmapEncoder();
BitmapFrame outputFrame = BitmapFrame.Create(bmp);
encoder.Frames.Add(outputFrame);
encoder.QualityLevel = quality;
using (FileStream file = File.OpenWrite(fileName))
{
encoder.Save(file);
}
}
}