■ PngBitmapEncoder 클래스를 사용해 PNG 파일을 생성하는 방법을 보여준다.
▶ 예제 코드 (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 |
using System.IO; using System.Windows.Media; using System.Windows.Media.Imaging; int width = 128; int height = 128; int stride = width; byte[] pixelByteArray = new byte[width * stride]; BitmapPalette bitmapPalette = BitmapPalettes.Halftone256; BitmapSource bitmapSource = BitmapSource.Create ( width, height, 96, 96, PixelFormats.Indexed8, bitmapPalette, pixelByteArray, stride ); FileStream stream = new FileStream("target.png", FileMode.Create); PngBitmapEncoder encoder = new PngBitmapEncoder(); encoder.Interlace = PngInterlaceOption.On; encoder.Frames.Add(BitmapFrame.Create(bitmapSource)); encoder.Save(stream); |