Files
Dario Sassi b329d5081e CameraMng :
- nuovo git per evitare problemi con bin e obj.
2025-08-31 17:11:40 +02:00

115 lines
3.4 KiB
VB.net

Imports System.Runtime.InteropServices
Imports System.Drawing.Imaging
Imports System.Drawing
Imports System.Drawing.Bitmap
Public Class BitmapBytesRGB24
' Provide public access to the picture's byte data.
Public ImageBytes() As Byte
Public RowSizeBytes As Integer
Public Const PixelDataSize As Integer = 24
' A reference to the Bitmap.
Private m_Bitmap As Drawing.Bitmap
' Bitmap data.
Private m_BitmapData As BitmapData
' Save a reference to the bitmap.
Public Sub New(ByVal bm As Drawing.Bitmap)
m_Bitmap = bm
End Sub
' Lock the bitmap's data.
Public Sub LockBitmap()
' Lock the bitmap data.
Dim bounds As Drawing.Rectangle = New Rectangle( _
0, 0, m_Bitmap.Width, m_Bitmap.Height)
m_BitmapData = m_Bitmap.LockBits(bounds, _
Imaging.ImageLockMode.ReadWrite, _
Imaging.PixelFormat.Format24bppRgb)
RowSizeBytes = m_BitmapData.Stride
' Allocate room for the data.
Dim total_size As Integer = m_BitmapData.Stride * m_BitmapData.Height
ReDim ImageBytes(total_size)
' Copy the data into the ImageBytes array.
Marshal.Copy(m_BitmapData.Scan0, ImageBytes, _
0, total_size)
End Sub
' Copy the data back into the Bitmap
' and release resources.
Public Sub UnlockBitmap()
' Copy the data back into the bitmap.
Dim total_size As Integer = m_BitmapData.Stride * m_BitmapData.Height
Marshal.Copy(ImageBytes, 0, _
m_BitmapData.Scan0, total_size)
' Unlock the bitmap.
m_Bitmap.UnlockBits(m_BitmapData)
' Release resources.
'ImageBytes = Nothing
'm_BitmapData = Nothing
End Sub
Public Sub ReleaseBitmap()
' Release resources.
ImageBytes = Nothing
m_BitmapData = Nothing
GC.Collect()
End Sub
End Class
Public Class BitmapBytes8
' Provide public access to the picture's byte data.
Public ImageBytes() As Byte
Public RowSizeBytes As Integer
Public Const PixelDataSize As Integer = 8
' A reference to the Bitmap.
Private m_Bitmap As Drawing.Bitmap
' Bitmap data.
Private m_BitmapData As BitmapData
' Save a reference to the bitmap.
Public Sub New(ByVal bm As Drawing.Bitmap)
m_Bitmap = bm
End Sub
' Lock the bitmap's data.
Public Sub LockBitmap()
' Lock the bitmap data.
Dim bounds As Drawing.Rectangle = New Rectangle(0, 0, m_Bitmap.Width, m_Bitmap.Height)
m_BitmapData = m_Bitmap.LockBits(bounds, Imaging.ImageLockMode.ReadWrite, _
m_Bitmap.PixelFormat)
RowSizeBytes = m_BitmapData.Stride
' Allocate room for the data.
Dim total_size As Integer = m_BitmapData.Stride * m_BitmapData.Height
ReDim ImageBytes(total_size)
' Copy the data into the ImageBytes array.
Marshal.Copy(m_BitmapData.Scan0, ImageBytes, 0, total_size)
End Sub
' Copy the data back into the Bitmap
' and release resources.
Public Sub UnlockAndCopyBitmap()
' Copy the data back into the bitmap.
Dim total_size As Integer = m_BitmapData.Stride * m_BitmapData.Height
Marshal.Copy(ImageBytes, 0, m_BitmapData.Scan0, total_size)
UnlockBitmap()
End Sub
' Release resources.
Public Sub UnlockBitmap()
m_Bitmap.UnlockBits(m_BitmapData)
End Sub
Public Sub ReleaseBitmap()
ImageBytes = Nothing
m_BitmapData = Nothing
GC.Collect()
End Sub
End Class