Results 1 to 4 of 4

Thread: Need help rewriting a jpg save

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2002
    Posts
    103

    Question 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.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    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)

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2002
    Posts
    103

    Re: Need help rewriting a jpg save

    .paul - thanks, but with the change you suggested, the failure mode is the same.

  4. #4
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,597

    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
  •  



Click Here to Expand Forum to Full Width