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
|
Class MainWindow
Dim myBmp As BitmapSource
Private Sub Window_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
'RECUPERE LE BitmapSource DU CONTROL Img
myBmp = CType(Me.Img.Source, BitmapSource)
Dim w As Integer = myBmp.PixelWidth
Dim h As Integer = myBmp.Height
Dim stride As Integer = myBmp.Format.BitsPerPixel * w
Dim nbPixel As Integer = stride * h
Dim arrPixels() As Byte = New Byte(nbPixel) {}
'COPIE TOUTE L'IMAGE DANS => arrPixels
myBmp.CopyPixels(arrPixels, stride, 0)
'COPIE ZONE D'IMAGE DANS => zonePixels
Dim srcRect As Int32Rect = New Int32Rect(100, 100, 300, 300)
Dim zonePixels(stride * srcRect.Height) As Byte
myBmp.CopyPixels(srcRect, zonePixels, stride, 0)
'CREE UN BitmapSource DE LA ZONE SPECIFIE ET L'AFFICHE DANS CONTROL ImgModified.
Dim tempBmpSource As BitmapSource = BitmapSource.Create(
srcRect.Width, srcRect.Height,
myBmp.DpiX, myBmp.DpiY,
myBmp.Format, Nothing,
zonePixels, stride)
Me.ImgModified.Source = tempBmpSource
End Sub
End Class |
Partager