Need to optimize a loop accessing an array and two bitmap objects
I have the following code. It's purpose it to take a source Bitmap object, read it and manipulate it throwing out an resulting Bitmap object. This should be done in realtime since it's done while moving the mouse over an image.
The code calling this method is managed, the bitmap objects are allocated as managed objects.
Now I wonder how I make the best optimization of this code. It might not mean that it should be unmanaged, just as fast as possible.
Private _ManipulationSize As Size
Private _XMap(,) As Integer
Private _YMap(,) As Integer
Public Function GenerateManipulated(ByVal Source As Bitmap) As Bitmap
Dim Dest As New Bitmap(Source)
Dim XCo As Integer, YCo As Integer
For YCo = 0 To Me._ManipulationSize.Height - 1
For XCo = 0 To Me._ManipulationSize.Width - 1
Dest.SetPixel(XCo, YCo, Source.GetPixel(_XMap(XCo, YCo), _YMap(XCo, YCo)))
Next
Next
Return Dest
End Function
Thanks..
/Frasse
I have the following code. It's purpose it to take a source Bitmap object, read it and manipulate it throwing out an resulting Bitmap object. This should be done in realtime since it's done while moving the mouse over an image.
The code calling this method is managed, the bitmap objects are allocated as managed objects.
Now I wonder how I make the best optimization of this code. It might not mean that it should be unmanaged, just as fast as possible.
Private _ManipulationSize As Size
Private _XMap(,) As Integer
Private _YMap(,) As Integer
Public Function GenerateManipulated(ByVal Source As Bitmap) As Bitmap
Dim Dest As New Bitmap(Source)
Dim XCo As Integer, YCo As Integer
For YCo = 0 To Me._ManipulationSize.Height - 1
For XCo = 0 To Me._ManipulationSize.Width - 1
Dest.SetPixel(XCo, YCo, Source.GetPixel(_XMap(XCo, YCo), _YMap(XCo, YCo)))
Next
Next
Return Dest
End Function
Thanks..
/Frasse