Saving Image From Clipboard

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • NoDozing
    New Member
    • Oct 2006
    • 3

    Saving Image From Clipboard

    Trying load an embedded object to the clipboard and then save it to a file. When I try and save to the file, I'm getting a "Object reference not set to an instance of an object". I've marked the line with ---->>> where the error occurs. Any help would be appreciated.

    Dim InShapeObj As Word.InlineShap e
    Dim SaveObj As New DataObject
    Dim ImageObj As Image
    Dim WordApp As New Word.Applicatio nClass
    WordApp.Visible = True
    Dim aDoc As Word.Document = WordApp.Documen ts.Open(Me.File Extract1.Text)
    Dim data As IDataObject = Clipboard.GetDa taObject()
    Dim fmt As String
    Dim FileName As String
    Dim MemStrm As MemoryStream
    aDoc.Activate()
    For Each InShapeObj In aDoc.InlineShap es
    If InShapeObj.OLEF ormat.IconLabel <> "" Then
    FileName = "c:\" + InShapeObj.OLEF ormat.IconLabel
    InShapeObj.Sele ct()
    ' WordApp.Selecti on.Copy()
    SaveObj.SetData (DataFormats.En hancedMetafile, WordApp.Selecti on)
    Clipboard.SetDa taObject(SaveOb j)
    SaveObj = Clipboard.GetDa taObject()
    If (SaveObj.GetDat aPresent(DataFo rmats.EnhancedM etafile)) Then
    ImageObj = Clipboard.GetDa taObject.GetDat a(DataFormats.E nhancedMetafile )
    --->>>>> ImageObj.Save(F ileName, System.Drawing. Imaging.ImageFo rmat.Emf)
    End If
    End If
    Next InShapeObj
  • willakawill
    Top Contributor
    • Oct 2006
    • 1646

    #2
    Originally posted by NoDozing
    Trying load an embedded object to the clipboard and then save it to a file. When I try and save to the file, I'm getting a "Object reference not set to an instance of an object". I've marked the line with ---->>> where the error occurs. Any help would be appreciated.

    Dim InShapeObj As Word.InlineShap e
    Dim SaveObj As New DataObject
    Dim ImageObj As Image
    Dim WordApp As New Word.Applicatio nClass
    WordApp.Visible = True
    Dim aDoc As Word.Document = WordApp.Documen ts.Open(Me.File Extract1.Text)
    Dim data As IDataObject = Clipboard.GetDa taObject()
    Dim fmt As String
    Dim FileName As String
    Dim MemStrm As MemoryStream
    aDoc.Activate()
    For Each InShapeObj In aDoc.InlineShap es
    If InShapeObj.OLEF ormat.IconLabel <> "" Then
    FileName = "c:\" + InShapeObj.OLEF ormat.IconLabel
    InShapeObj.Sele ct()
    ' WordApp.Selecti on.Copy()
    SaveObj.SetData (DataFormats.En hancedMetafile, WordApp.Selecti on)
    Clipboard.SetDa taObject(SaveOb j)
    SaveObj = Clipboard.GetDa taObject()
    If (SaveObj.GetDat aPresent(DataFo rmats.EnhancedM etafile)) Then
    ImageObj = Clipboard.GetDa taObject.GetDat a(DataFormats.E nhancedMetafile )
    --->>>>> ImageObj.Save(F ileName, System.Drawing. Imaging.ImageFo rmat.Emf)
    End If
    End If
    Next InShapeObj
    Perhaps this will work better:
    Set ImageObj = Clipboard.GetDa taObject.GetDat a(DataFormats.E nhanc edMetafile)

    Comment

    • NoDozing
      New Member
      • Oct 2006
      • 3

      #3
      Originally posted by willakawill
      Perhaps this will work better:
      Set ImageObj = Clipboard.GetDa taObject.GetDat a(DataFormats.E nhanc edMetafile)

      Thanks, but when I put the SET in front, it goes away when I leave the line, in Studio. So, this didn't work.

      Comment

      • willakawill
        Top Contributor
        • Oct 2006
        • 1646

        #4
        Originally posted by NoDozing
        Thanks, but when I put the SET in front, it goes away when I leave the line, in Studio. So, this didn't work.
        I can see a 'SetData()' and 'GetData()' set of methods for clipboard but I can't see 'SetDataObject( )' or 'GetDataObject( )'

        Do these methods appear on your intellisense?

        Comment

        Working...