If I set CloneFirst =True, the image is displayed as expected. If i Set CloneFirst =False the image is displayed pixelated. Can someone please explain to me why this is happening.
VB.NET:
Private Const FILE_PATH As String = "staticmap.jpeg"
Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
Dim imageFile As New IO.FileInfo(FILE_PATH)
Dim newBitMap As Bitmap = CType(Bitmap.FromStream(imageFile.OpenRead), Bitmap)
Dim clonedBitMap As Bitmap
clonedBitMap = getBitMap(newBitMap, ckbCloneFirst.Checked)
pbImage.Image = clonedBitMap
End Sub
Private Function getBitMap(ByVal BottomImage As Bitmap, ByVal CloneFirst As Boolean) As Bitmap
Dim CopiedBottomImage As Bitmap = DirectCast(BottomImage.Clone(), Bitmap)
Dim CopiedImageGraphics As Graphics
Dim otherImage As Bitmap
If CloneFirst Then
otherImage = DirectCast(BottomImage.Clone(), Bitmap)
CopiedImageGraphics = Graphics.FromImage(CopiedBottomImage)
Else
CopiedImageGraphics = Graphics.FromImage(CopiedBottomImage)
otherImage = DirectCast(BottomImage.Clone(), Bitmap)
End If
'otherImage.Dispose()
'BottomImage.Dispose()
'' secondImage.Dispose()
'CopiedImageGraphics.Dispose()
Return CopiedBottomImage
End Function