VB.Net中,将剪切板上的图片粘贴到RichTextBox,当GetImage无效时,怎样将剪切板上未知格式的图像(或位图等等)转换为Bmp格式
Dim DataObject1 As DataObject = Clipboard.GetDataObject()
'判断可以转换的格式,Bitmap总是可以通过
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
Else
ImageFormat1 = System.Drawing.Imaging.ImageFormat.Jpeg
End If
Dim ImageName As String
Dim Image1 As Image = DataObject1.GetImage() '剪切后直接粘贴,则可行
'但例如,从QQ复制的图片,是Png格式的文件,但不在DataObject1.ContainsFileDropList,而上述GetImage方法也无法获得
If Image1 Is Nothing Then
Dim J As Integer, MemoryStream1 As System.IO.MemoryStream = Nothing
Dim STR1() As String = DataObject1.GetFormats()
For J = 0 To STR1.Count - 1 Step 1
MemoryStream1 = DataObject1.GetData(STR1(J), True)
If MemoryStream1 IsNot Nothing Then Exit For
Next J
Image1 = Image.FromStream(MemoryStream1, True, True) '出错,参数无效,应该是MemoryStream1问题
ImageName = "" '怎样获得该图形文件原来的文件名
Else
ImageName = "D:\Image1.bmp"
End If
Image1.Save(ImageName, ImageFormat1)
剪切板上有多种格式内容: 多个文件、多个截图、多行文本,请教以下问题:
1. 怎样将剪切板上未知格式的图形文件,转换为Bmp格式
2. 怎样获得该图形文件原来的文件名
在这里,恳请不愿意回答的朋友不要作一些似是而非的答案,不愿意回答就不要作答!以免愿意回答的其他朋友出于避免抢题而回避了,谢谢各位!
相关推荐
VB.NET将图片插入数据库代码
VB.NET开服图片数据库应用程序将图片插入数据库代码面积分下载
VB.net捕获整个网页并保存成图像
VB.net捕获整个网页并保存成图像有软件 Private Sub GetImage() If WebBrowser1.Document Is Nothing Then Return End If Try Dim scrollWidth As Integer Dim scrollHeight As Integer scrollHeight = WebBrowser1.Document.Body.ScrollRectangle.Height scrollWidth = WebBrowser1.Document.Body.ScrollRectangle.Width WebBrowser1.Size = New Size(scrollWidth, scrollHeight) Dim bm As New Bitmap(scrollWidth, scrollHeight) WebBrowser1.DrawToBitmap(bm, New Rectangle(0, 0, bm.Width, bm.Height)) Dim SaveAsName As String SaveAsName = Regex.Replace(textWebURL.Text, "(\\|\/|\:|\*|\?|\""|\<|\>|\|)?", "") bm.Save(SaveAsName & ".png", System.Drawing.Imaging.ImageFormat.Png) bm.Dispose() Catch ex As Exception MessageBox.Show(ex.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error) Finally ' End Try buttonCapture.Enabled = True End Sub
VB.Net剪贴板示例.txt
VB.Net剪贴板示例.txtVB.Net剪贴板示例.txt
VB.NET Clipboard sample code
VB.NET Clipboard sample code
C#/VB.NET 在Word中添加条码、二维码的示例代码
主要介绍了C#/VB.NET 如何在Word中添加条码、二维码,代码中将分为在Word正文段落中、页眉页脚中等情况来添加。感兴趣的朋友可以了解下


