Out Of Memory - What ?

  • Thread starter Thread starter Devon_Nullman
  • Start date Start date
D

Devon_Nullman

Guest
I have an image with 20 pictures of elements as they would show in a Periodic Table - I want to extract (clone) each image in the source and save in a separate jpeg file. After 16 images are saved, I get an Out Of Memory exception which doesn't make sense, I have 8 GB of memory, nothing else is running. Here is the code:

Private Sub BtnMakeElements_Click(sender As Object, e As EventArgs) Handles BtnMakeElements.Click
Dim BM As Bitmap = Bitmap.FromFile("D:\Elements\01-20.jpg")
Dim FName As String = ""
Dim Format As System.Drawing.Imaging.PixelFormat = BM.PixelFormat
Dim x As Integer = 0
Dim y As Integer = 0
Dim ReF As New RectangleF
For row As Integer = 3 To 4
For column As Integer = 0 To 3
x = 2 + (column * 134)
y = row * 157
FName = "D:\Elements\" & ((row * 4) + column + 1).ToString("00") & ".jpg"
ReF = New RectangleF(New Point(x, y), New Size(120, 120))
Dim DestBM As Bitmap = New Bitmap(120, 120)
DestBM = BM.Clone(ReF, Format)
DestBM.Save(FName, ImageFormat.Jpeg)
DestBM.Dispose()
Next
Next
End Sub


Here is the "source image"

1346450.jpg

Any ideas as to what I am missing / doing wrong would be great to hear.

Continue reading...
 
Back
Top