画像用の WinRT (Metro) オブジェクトのいくつかを操作する方法を学ぼうとしています。基本的に、使いやすい "GetPixel" および "SetPixel" メソッドの作成に取り組んでいます (Metro アプリでは使用できない System.Drawing.Bitmap にあるものと同様)。
テストのために、「ビットマップ」クラスを作成しました。Metro ファイル ピッカー コントロールから取得した IRandomAccessStream に基づいてロードします。ピクセル データを Byte 配列に読み込み、そこから BitmapImage を作成できます。この BitmapImage は、Image コントロールに投げると XAML フォームで正しくレンダリングされます。
これが私の問題です。バイト配列を見て、個々の ARGB 値を確認できますが、本来よりもはるかに少ないピクセルを持っています。たとえば、読み込んでいる画像は 254x197 ピクセル (254*197*4=200,152) です。以下のコードを使用して Byte 配列をロードすると、16,382 バイトしかありません (これも 4 で均等に除算されません)。これは圧縮されていると思いますか?..わかりません。
私の質問は、私は何を間違っているのですか.. GetPixel(x,y) および SetPixel(x,y,Color) メソッドを作成できるように、必要な 50,038 ピクセルを表す 200,152 バイトを返したいと思います。
Public Class Bitmap
Public Sub New()
End Sub
Public Async Function Load(s As Windows.Storage.Streams.IRandomAccessStream) As Task
Dim dr As New DataReader(s.GetInputStreamAt(0))
Await dr.LoadAsync(s.Size)
Me.Pixels = New Byte(s.Size - 1) {}
dr.ReadBytes(Me.Pixels)
' We're going to get the height and the width of the image this way. ;)
Dim bi As New BitmapImage
Dim stream As New MemoryStream(Me.Pixels)
bi.SetSource(New RandomStream(stream))
Me.Width = bi.PixelWidth
Me.Height = bi.PixelHeight
End Function
Public Function ToBitmapImage() As BitmapImage
Dim bi As New BitmapImage
Dim stream As New MemoryStream(Me.Pixels)
bi.SetSource(New RandomStream(stream))
Return bi
End Function
Public Property Pixels As Byte()
Public Property Width As Integer = 0
Public Property Height As Integer = 0
End Class