File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed
Microsoft.VisualBasic.Core/src/Drawing/Bitmap Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -204,6 +204,18 @@ Namespace Imaging.BitmapImage
204204 _Height = size.Height
205205 End Sub
206206
207+ Sub New (pixels As Color(), size As Size)
208+ Call MyBase .New(Unpack(pixels, size))
209+
210+ channels = TYPE_INT_ARGB ' argb
211+ memoryBuffer = True
212+
213+ _Stride = size.Width * channels
214+ _Size = size
215+ _Width = size.Width
216+ _Height = size.Height
217+ End Sub
218+
207219 Public Const TYPE_INT_RGB As Integer = 3
208220 Public Const TYPE_INT_ARGB As Integer = 4
209221
@@ -545,6 +557,36 @@ Namespace Imaging.BitmapImage
545557 Return color
546558 End Function
547559
560+ ''' <summary>
561+ ''' argb channels=4
562+ ''' </summary>
563+ ''' <param name="pixels"></param>
564+ ''' <param name="size"></param>
565+ ''' <returns></returns>
566+ Public Shared Function Unpack(pixels As Color(), size As Size) As Byte ()
567+ Dim bytes As Byte () = New Byte (TYPE_INT_ARGB * size.Width * size.Height - 1 ) {}
568+
569+ ' If channels = TYPE_INT_ARGB Then
570+ ' iA = buffer(i + 3)
571+ ' End If
572+
573+ ' Dim iR As Byte = buffer(i + 2)
574+ ' Dim iG As Byte = buffer(i + 1)
575+ ' Dim iB As Byte = buffer(i + 0)
576+
577+ For i As Integer = 0 To pixels.Length - 1 Step TYPE_INT_ARGB
578+ Dim pixel As Color = pixels(i)
579+
580+ bytes(i + 3 ) = pixel.A
581+
582+ bytes(i + 2 ) = pixel.R
583+ bytes(i + 1 ) = pixel.G
584+ bytes(i + 0 ) = pixel.B
585+ Next
586+
587+ Return bytes
588+ End Function
589+
548590 ''' <summary>
549591 ''' argb channels=4
550592 ''' </summary>
You can’t perform that action at this time.
0 commit comments