Dim DataObject1 As DataObject=Clipboard. GetDataObject ()
'judgment can convert the format, Bitmap can always through
If DataObject1. GetDataPresent (DataFormats. Bitmap)=True Then
ImageFormat1=System. Drawing. Imaging. ImageFormat. Bmp
ElseIf DataObject1. GetDataPresent (DataFormats. Tiff)=True Then
ImageFormat1=System. Drawing. Imaging. ImageFormat. Tiff
ElseIf DataObject1. GetDataPresent (DataFormats. EnhancedMetafile)=True Then
ImageFormat1=System. Drawing. Imaging. ImageFormat. Emf
ElseIf DataObject1. GetDataPresent (DataFormats. MetafilePict)=True Then
ImageFormat1=System. Drawing. Imaging. ImageFormat. Wmf
ElseIf DataObject1. GetDataPresent (DataFormats. Dib)=True Then
ImageFormat1=System. Drawing. Imaging. ImageFormat. MemoryBmp
The Else
ImageFormat1=System. Drawing. Imaging. ImageFormat. Jpeg
End the If
Dim ImageName As String
Dim Image1 As Image=DataObject1. GetImage () 'paste directly after shearing, the feasible
'but copy pictures from QQ, for example, is a Png format file, but not DataObject1. ContainsFileDropList, while the GetImage method could not obtain
If Image1 Is Nothing Then
Dim J As an Integer, MemoryStream1 the As System. IO. MemoryStream=Nothing
Dim STR1 () As String=DataObject1. GetFormats ()
For J=0 To STR1. Step 1 Count - 1
MemoryStream1=DataObject1. GetData (STR1 (J), True)
If MemoryStream1 IsNot Nothing Then Exit the For
Next J
Image1=Image. FromStream (MemoryStream1, True, True) 'error, the parameter is invalid, should be MemoryStream1 problems
ImageName="" 'how to get the graphics file of the original file name
The Else
ImageName="D: \ Image1. BMP"
End the If
Image1. Save (ImageName ImageFormat1)
Shear plate has a variety of formats: multiple files, multiple screenshots, multiline text, consult the following problems:
1. How the clipboard on the unknown graphics file format, are converted into Bmp format
2. How to get the graphics file of the original file name
Here, I don't want to answer some friends do not be instead of the answer, don't want to answer don't answer! In order to avoid other friends willing to answer to avoid rob and avoided, thank you!
CodePudding user response:
Problem has been resolved,It turns out that after the screenshot, directly into RichTextBox paste, to judge; for the picture
And if the screenshot, in QQ or WeChat input box, has already become a file, and then copy, RichTextBox paste that, at this point, the DataObject1. ContainsImage and DataObject1 ContainsFileDropList all judgment is True, use DataObject1. GetImage () to the operation, is the problem the provenance,
Judge clipboard file, and then judge images, to avoid repetition and dealing with the same content,