BitmapSource.Create Method (Int32, Int32, Double, Double, PixelFormat, BitmapPalette, Array, Int32)

 

Creates a new BitmapSource from an array of pixels.

Namespace:   System.Windows.Media.Imaging
Assembly:  PresentationCore (in PresentationCore.dll)

Public Shared Function Create (
	pixelWidth As Integer,
	pixelHeight As Integer,
	dpiX As Double,
	dpiY As Double,
	pixelFormat As PixelFormat,
	palette As BitmapPalette,
	pixels As Array,
	stride As Integer
) As BitmapSource

Parameters

pixelWidth
Type: System.Int32

The width of the bitmap.

pixelHeight
Type: System.Int32

The height of the bitmap.

dpiX
Type: System.Double

The horizontal dots per inch (dpi) of the bitmap.

dpiY
Type: System.Double

The vertical dots per inch (dpi) of the bitmap.

pixelFormat
Type: System.Windows.Media.PixelFormat

The pixel format of the bitmap.

palette
Type: System.Windows.Media.Imaging.BitmapPalette

The palette of the bitmap.

pixels
Type: System.Array

An array of bytes that represents the content of a bitmap image.

stride
Type: System.Int32

The stride of the bitmap.

Return Value

Type: System.Windows.Media.Imaging.BitmapSource

The BitmapSource that is created from the specified array of pixels.

The following example demonstrates how to use this method in order to create a new BitmapSource.

Dim width As Integer = 128
Dim height As Integer = width
Dim stride As Integer = CType(width / 8, Integer)
Dim pixels(height * stride) As Byte

' Try creating a new image with a custom palette.
Dim colors As New List(Of System.Windows.Media.Color)()
colors.Add(System.Windows.Media.Colors.Red)
colors.Add(System.Windows.Media.Colors.Blue)
colors.Add(System.Windows.Media.Colors.Green)
Dim myPalette As New BitmapPalette(colors)

' Creates a new empty image with the pre-defined palette
Dim image As BitmapSource = System.Windows.Media.Imaging.BitmapSource.Create(width, height, 96, 96, PixelFormats.Indexed1, myPalette, pixels, stride)
Dim stream As New FileStream("empty.tif", FileMode.Create)
Dim encoder As New TiffBitmapEncoder()
Dim myTextBlock As New TextBlock()
myTextBlock.Text = "Codec Author is: " + encoder.CodecInfo.Author.ToString()
encoder.Frames.Add(BitmapFrame.Create(image))
MessageBox.Show(myPalette.Colors.Count.ToString())
encoder.Save(stream)

.NET Framework
Available since 3.0
Return to top
Show: