-
May 20th, 2021, 04:02 PM
#1
Thread Starter
Lively Member
Need help rewriting a jpg save
My code, very simpleminded, looks like this:
Code:
Dim bmp As Bitmap
Dim bmpSave As Bitmap
bmp = drawImage() ' function than returns a bitmap
If something Then
bmpSave = ' type bitmap
Else
bmpSave = bmp
End If
bmpSave.Save(<filename>, ImageFormat.Jpeg)
The first time through, something is false and the code writes the file. The second time through, something is false and the code does not write the file. Even worse, the code hangs on the last line.
I have tried adding bmpSave.Dispose after the Save method, but that didn't help. I suspect that <filename> is still opened and that is the problem. Please suggest that which I can do to make this work. Thanks.
-
May 20th, 2021, 08:50 PM
#2
Re: Need help rewriting a jpg save
Try...
Code:
Dim bmp As Bitmap
Dim bmpSave As Bitmap
bmp = drawImage() ' function than returns a bitmap
If something Then
bmpSave = ' type bitmap
Else
bmpSave = bmp
End If
Dim img as New BitMap(bmpSave)
bmpSave.Dispose
img.Save(<filename>, ImageFormat.Jpeg)
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 21st, 2021, 01:42 PM
#3
Thread Starter
Lively Member
Re: Need help rewriting a jpg save
.paul - thanks, but with the change you suggested, the failure mode is the same.
-
May 21st, 2021, 05:15 PM
#4
Re: Need help rewriting a jpg save
How about trying to auto dispose it with using?
Code:
Using bmp = New Bitmap(Mymage.DWidht, Mymage.Dheight)
.. blah blah
img.Save(<filename>, ImageFormat.Jpeg)
'and as a last resort use a dispose here if it does not work, but only
bmp.dispose()
end using
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|