diff --git a/Data_science/MachineLearning/DeepLearning/CeNiN/Layers/Input.vb b/Data_science/MachineLearning/DeepLearning/CeNiN/Layers/Input.vb
index 4ae918448a..fa1abcb373 100644
--- a/Data_science/MachineLearning/DeepLearning/CeNiN/Layers/Input.vb
+++ b/Data_science/MachineLearning/DeepLearning/CeNiN/Layers/Input.vb
@@ -62,6 +62,8 @@ Imports System.Runtime.CompilerServices
Imports System.Runtime.InteropServices
Imports Microsoft.VisualBasic.MachineLearning.Convolutional.ImageProcessor
Imports System.Drawing
+Imports Microsoft.VisualBasic.Imaging.BitmapImage
+
#If NET48 Then
Imports Pen = System.Drawing.Pen
@@ -142,7 +144,7 @@ Namespace Convolutional
'''
Public Overrides Function feedNext() As Layer
Dim fullImage As New Rectangle(0, 0, inputSize(1), inputSize(0))
- Dim bmpData As BitmapData = _resizedInputBmp.LockBits(fullImage, ImageLockMode.ReadOnly, _resizedInputBmp.PixelFormat)
+ Dim bmpData As BitmapBuffer = BitmapBuffer.FromBitmap(_resizedInputBmp)
Dim stride As Integer = bmpData.Stride
Dim emptyBytesCount As Integer = stride - bmpData.Width * 3
Dim rowLengthWithoutEB As Integer = stride - emptyBytesCount
@@ -178,7 +180,6 @@ Namespace Convolutional
End If
End While
- Call _resizedInputBmp.UnlockBits(bmpData)
Call _resizedInputBmp.Dispose()
Return Me
diff --git a/Data_science/MachineLearning/MLDataStorage/MNIST.vb b/Data_science/MachineLearning/MLDataStorage/MNIST.vb
index ff9b8273fc..76067d629b 100644
--- a/Data_science/MachineLearning/MLDataStorage/MNIST.vb
+++ b/Data_science/MachineLearning/MLDataStorage/MNIST.vb
@@ -65,6 +65,8 @@ Imports System.Runtime.CompilerServices
Imports System.Runtime.InteropServices
Imports Microsoft.VisualBasic.ComponentModel.DataSourceModel
Imports std = System.Math
+Imports Microsoft.VisualBasic.Imaging.BitmapImage
+
#If NET48 Then
Imports Pen = System.Drawing.Pen
@@ -168,7 +170,7 @@ Public Class MNIST : Implements IDisposable
Public Function ConvertImage(raw As NamedCollection(Of Byte)) As NamedValue(Of Image)
Dim image As Bitmap = New Bitmap(columns, rows)
- Dim data = image.LockBits(rect, ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb)
+ Dim data As BitmapBuffer = BitmapBuffer.FromBitmap(image)
Dim ptr As IntPtr = data.Scan0
Dim bytes = std.Abs(data.Stride) * image.Height
Dim rgbValues = New Byte(bytes - 1) {}
@@ -184,8 +186,7 @@ Public Class MNIST : Implements IDisposable
Next
Marshal.Copy(rgbValues, 0, ptr, bytes)
-
- image.UnlockBits(data)
+ data.Dispose()
Return New NamedValue(Of Image) With {
.Name = raw.Last,
diff --git a/Data_science/Visualization/Visualization/Embedding/EmbeddingRender.vb b/Data_science/Visualization/Visualization/Embedding/EmbeddingRender.vb
index 24b0eec605..fb02d4eb54 100644
--- a/Data_science/Visualization/Visualization/Embedding/EmbeddingRender.vb
+++ b/Data_science/Visualization/Visualization/Embedding/EmbeddingRender.vb
@@ -56,10 +56,17 @@ Imports System.Drawing
Imports Microsoft.VisualBasic.Data.ChartPlots.Graphic
Imports Microsoft.VisualBasic.Data.ChartPlots.Graphic.Canvas
Imports Microsoft.VisualBasic.DataMining.ComponentModel
-Imports Microsoft.VisualBasic.DataMining.UMAP
Imports Microsoft.VisualBasic.Imaging.Drawing2D.Colors
Imports Microsoft.VisualBasic.Linq
+#If NET48 Then
+Imports SolidBrush = System.Drawing.SolidBrush
+Imports Brushes = System.Drawing.Brushes
+#Else
+Imports SolidBrush = Microsoft.VisualBasic.Imaging.SolidBrush
+Imports Brushes = Microsoft.VisualBasic.Imaging.Brushes
+#End If
+
Public MustInherit Class EmbeddingRender : Inherits Plot
Protected ReadOnly labels As String()
diff --git a/Microsoft.VisualBasic.Core/src/Drawing/GDI+/GraphicsExtensions.vb b/Microsoft.VisualBasic.Core/src/Drawing/GDI+/GraphicsExtensions.vb
index 44040a70fb..a64fb8eb41 100644
--- a/Microsoft.VisualBasic.Core/src/Drawing/GDI+/GraphicsExtensions.vb
+++ b/Microsoft.VisualBasic.Core/src/Drawing/GDI+/GraphicsExtensions.vb
@@ -67,6 +67,7 @@ Imports System.Runtime.CompilerServices
Imports System.Runtime.InteropServices
Imports Microsoft.VisualBasic.CommandLine.Reflection
Imports Microsoft.VisualBasic.ComponentModel.Algorithm.base
+Imports Microsoft.VisualBasic.Imaging.BitmapImage
Imports Microsoft.VisualBasic.Language
Imports Microsoft.VisualBasic.Linq
Imports Microsoft.VisualBasic.Net.Http
@@ -407,6 +408,36 @@ Namespace Imaging
End With
End Function
+ '''
+ ''' Color replace using memory pointer
+ '''
+ '''
+ '''
+ '''
+ '''
+
+ Public Function ColorReplace(image As Bitmap, subject As Color, replaceAs As Color, Optional tolerance% = 3) As Bitmap
+ Using bitmap As BitmapBuffer = BitmapBuffer.FromBitmap(image)
+ Dim byts As BitmapBuffer = bitmap
+
+ For x As Integer = 0 To byts.Width - 1
+ For y As Integer = 0 To byts.Height - 1
+ If GDIColors.Equals(byts.GetPixel(x, y), subject, tolerance) Then
+ Call byts.SetPixel(x, y, replaceAs)
+ End If
+ Next
+ Next
+ End Using
+
+ Return image
+ End Function
+
+
+
+ Public Function ColorReplace(image As Image, subject As Color, replaceAs As Color, Optional tolerance% = 3) As Bitmap
+ Return New Bitmap(image).ColorReplace(subject, replaceAs, tolerance)
+ End Function
+
'''
''' Adding a frame box to the target image source.(为图像添加边框)
'''
diff --git a/gr/Drawing-net4.8/Utils.vb b/gr/Drawing-net4.8/Utils.vb
index d82eb40587..d9b675ff3c 100644
--- a/gr/Drawing-net4.8/Utils.vb
+++ b/gr/Drawing-net4.8/Utils.vb
@@ -275,35 +275,5 @@ Namespace Imaging.BitmapImage
Return res
End If
End Function
-
- '''
- ''' Color replace using memory pointer
- '''
- '''
- '''
- '''
- '''
-
- Public Function ColorReplace(image As Bitmap, subject As Color, replaceAs As Color, Optional tolerance% = 3) As Bitmap
- Using bitmap As BitmapBuffer = BitmapBuffer.FromBitmap(image)
- Dim byts As BitmapBuffer = bitmap
-
- For x As Integer = 0 To byts.Width - 1
- For y As Integer = 0 To byts.Height - 1
- If GDIColors.Equals(byts.GetPixel(x, y), subject, tolerance) Then
- Call byts.SetPixel(x, y, replaceAs)
- End If
- Next
- Next
- End Using
-
- Return image
- End Function
-
-
-
- Public Function ColorReplace(image As Image, subject As Color, replaceAs As Color, Optional tolerance% = 3) As Bitmap
- Return New Bitmap(image).ColorReplace(subject, replaceAs, tolerance)
- End Function
End Module
End Namespace