■ JpegBitmapEncoder 클래스를 사용해 JPG 파일을 생성하는 방법을 보여준다.
▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
using System.IO; using System.Windows.Media; using System.Windows.Media.Imaging; int width = 128; int height = width; int stride = width / 8; byte[] pixelByteArray = new byte[height * stride]; BitmapPalette bitmapPalette = BitmapPalettes.Halftone256; BitmapSource bitmapSource = BitmapSource.Create ( width, height, 96, 96, PixelFormats.Indexed1, bitmapPalette, pixelByteArray, stride ); FileStream stream = new FileStream("target.jpg", FileMode.Create); JpegBitmapEncoder encoder = new JpegBitmapEncoder(); encoder.FlipHorizontal = true; encoder.FlipVertical = false; encoder.QualityLevel = 30; encoder.Rotation = Rotation.Rotate90; encoder.Frames.Add(BitmapFrame.Create(bitmapSource)); encoder.Save(stream); |