none
How to Close a bmp file in VB RRS feed

  • Question

  • I wrote a code to get the screen hardcopy of a oscilloscope to be saved.

    At the first time, the SAVE is OK. But,I want to save it (bm.save) again to the same file.

    The following exception happens. How can I fix it? 

    "System.Runtime.InteropServices.ExternalException: 'A generic error occurred in GDI+.'"

            WaveformBox.SizeMode = PictureBoxSizeMode.StretchImage
            WaveformBox.Image = Nothing
            MsgBox("GetHardCopy")
            TekScope.HardcopyToClipboard()
            WaveformBox.Image = Clipboard.GetImage
            MsgBox("Save Groupbox Image")
            Using bm As New Bitmap(GroupBox1.Width, GroupBox1.Height)
                GroupBox1.DrawToBitmap(bm, New Rectangle(0, 0, bm.Width, bm.Height))
                bm.Save("D:\temp\GroupBoxImage.bmp", Imaging.ImageFormat.Bmp)
            End Using
            MsgBox("Show Image File")
            WaveformBox.Image = Image.FromFile("D:\temp\GroupBoxImage.bmp")

    Thursday, August 1, 2019 4:08 AM

Answers

  • Try this (instead of last line):

       WaveformStream = New MemoryStream(File.ReadAllBytes("D:\temp\GroupBoxImage.bmp"))

       WaveformBox.Image = Image.FromStream(WaveformStream)

    Also add a new member to your class (form):

       Private WaveformStream As Stream

     


    Thursday, August 1, 2019 5:03 AM

All replies

  • Try this (instead of last line):

       WaveformStream = New MemoryStream(File.ReadAllBytes("D:\temp\GroupBoxImage.bmp"))

       WaveformBox.Image = Image.FromStream(WaveformStream)

    Also add a new member to your class (form):

       Private WaveformStream As Stream

     


    Thursday, August 1, 2019 5:03 AM
  • Many Thanks! Solve my problem!
    Thursday, August 1, 2019 5:27 AM
  • Hi,

    I am glad you have got your solution,please mark the useful replies as answers.

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, August 5, 2019 6:04 AM