I have an application which creates a Bitmap
object consisting of all the 16 million colors. The final bitmap would be measuring 4096 × 4096 pixels.
When I try to call the Bitmap's Save()
method, it causes an error.
This is the error message that comes up:
A generic error occurred in GDI+.
Please try to help me on this thing. Thanks in advance!
Note: Look at the last few commented lines of the source code below. I have explained the doubt there.
SOURCE CODE:
Public Sub CreateAllColorImage()
Dim BMP As New Bitmap(4096, 4096) 'This BMP variable is where the image will be created.'
Dim CurrX = 0
Dim CurrY = 0
Dim ExitFors As Boolean = False
For R = 0 To 255
For G = 0 To 255
For B = 0 To 255
BMP.SetPixel(CurrX, CurrY, Color.FromArgb(R, G, B))
CurrY += 1 'Increment the Y axis to move to next pixel.'
If CurrY > 4095 Then CurrX += 1 : CurrY = 0 'Move to next row, or increment X axis, if the last pixel on the Y axis is reached'
If CurrX > 4095 Then ExitFors = True 'Set the variable to exit the FOR loops if the very last pixel on the whole image is reached.'
If ExitFors Then Exit For 'Exit the FOR loop if the variable is true.'
Next
If ExitFors Then Exit For 'Exit the FOR loop if the variable is true.'
Next
If ExitFors Then Exit For 'Exit the FOR loop if the variable is true.'
Next
'So therefore, the final image is the BMP variable.'
'Here, I try to save the Bitmap as a file by calling this:'
BMP.Save("C:\TEST.BMP")
'This is when the error occurs. I think so because of the image is too large. If so, is there any way to do anything?'
'And by the way, I already have the rights to access the C:\ drive because I am working from an Administrator account...'
BMP.Dispose()
BMP = Nothing
End Sub