This repository has been archived by the owner on Apr 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGraphicsCustom.vb
63 lines (51 loc) · 2.45 KB
/
GraphicsCustom.vb
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
Imports hamarb123.VBUMIP.Desktop.ImageCustom
#If DESKTOP = True Then
Imports Image = System.Drawing.Image
Imports Graphics = System.Drawing.Graphics
Imports Size = System.Drawing.Size
Imports CompositingMode = System.Drawing.Drawing2D.CompositingMode
Imports InterpolationMode = System.Drawing.Drawing2D.InterpolationMode
Imports PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode
Imports CompositingQuality = System.Drawing.Drawing2D.CompositingQuality
Imports Rectangle = System.Drawing.Rectangle
Imports Bitmap = System.Drawing.Bitmap
Imports PixelFormat = System.Drawing.Imaging.PixelFormat
Imports ImageLockMode = System.Drawing.Imaging.ImageLockMode
Imports System.Linq.Enumerable
Imports Enumerable = System.Linq.Enumerable
Imports Marshal = System.Runtime.InteropServices.Marshal
#End If
Public NotInheritable Class GraphicsCustom
#If DESKTOP = True Then
Public Sub New(size As Size)
Me.ImageSize = size
Me.L = Enumerable.Repeat(Of Byte)(Nothing, size.Height * size.Width * BPP).ToArray()
End Sub
Public ReadOnly ImageSize As Size
Public L As Byte()
Public Sub Invalidate(getGraphics As Func(Of Graphics), renderSize As Size)
Dim mybytearray As Byte() = Me.L
Dim x1 As Image = ImageFromRawBgraArray(mybytearray, Me.ImageSize.Width, Me.ImageSize.Height, PixelFormat.Format32bppArgb)
Dim g = getGraphics.Invoke
g.CompositingMode = CompositingMode.SourceCopy
g.InterpolationMode = InterpolationMode.NearestNeighbor
g.PixelOffsetMode = PixelOffsetMode.Half
g.CompositingQuality = CompositingQuality.Default
Dim drawRectangle As Rectangle
drawRectangle = New Rectangle(0, 0, renderSize.Width, renderSize.Height)
g.DrawImage(x1, drawRectangle)
g.Dispose()
x1.Dispose()
End Sub
Public Shared Function ImageFromRawBgraArray(arr As Byte(), width As Integer, height As Integer, pixelFormat As PixelFormat) As Image
Dim output = New Bitmap(width, height, pixelFormat)
Dim rect = New Rectangle(0, 0, width, height)
Dim bmpData = output.LockBits(rect, ImageLockMode.ReadWrite, output.PixelFormat)
Dim arrLength = width * CInt(Image.GetPixelFormatSize(output.PixelFormat) / 8) * height
Dim ptr = bmpData.Scan0
Marshal.Copy(arr, 0, ptr, arrLength)
output.UnlockBits(bmpData)
Return output
End Function
#End If
End Class