다음을 통해 공유


방법: 새 BitmapSource 만들기

이 예제에서는 BitmapSourceCreate 메서드를 사용하여 새 BitmapSource 개체를 만드는 방법을 보여 줍니다.

예제

// Define parameters used to create the BitmapSource.
PixelFormat pf = PixelFormats.Bgr32;
int width = 200;
int height = 200;
int rawStride = (width * pf.BitsPerPixel + 7) / 8;
byte[] rawImage = new byte[rawStride * height];

// Initialize the image with data.
Random value = new Random();
value.NextBytes(rawImage);

// Create a BitmapSource.
BitmapSource bitmap = BitmapSource.Create(width, height,
    96, 96, pf, null,
    rawImage, rawStride);

// Create an image element;
Image myImage = new Image();
myImage.Width = 200;
// Set image source.
myImage.Source = bitmap;
' Define parameters used to create the BitmapSource.
Dim pf As PixelFormat = PixelFormats.Bgr32
Dim width As Integer = 200
Dim height As Integer = 200
Dim rawStride As Integer = CType((width * pf.BitsPerPixel + 7) / 8, Integer)
Dim rawImage(rawStride * height) As Byte

' Initialize the image with data.
Dim value As New Random()
value.NextBytes(rawImage)

' Create a BitmapSource.
Dim bitmap As BitmapSource = BitmapSource.Create(width, height, 96, 96, pf, Nothing, rawImage, rawStride)

' Create an image element;
Dim myImage As New Image()
myImage.Width = 200
' Set image source.
myImage.Source = bitmap

참고 항목