VB.Net RichTextBox图像质量 [英] VB.Net RichTextBox Image quality

查看:127
本文介绍了VB.Net RichTextBox图像质量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在使用我正在构建的Windows窗体应用程序遇到麻烦。用户希望对表单进行控制,以便将格式化的文本和图像粘贴到其中。我使用过RichTextBox,但粘贴后的图像质量很差,与原版相比非常低劣。它也不允许调整图像的大小。



我有什么方法可以纠正这些缺陷,或者我只是采取了错误的方法?有没有我应该考虑的替代方案?



谢谢,



Tony。

解决方案

嗨Tony,



这是将图像插入RichTextBox的代码,这将允许用户调整图像大小但是调整大小时图像质量非常差(除非在打印预览对话框中)。



 公开  Sub  InsertPicture()
尝试
< span class =code-keyword> Dim GetPicture As OpenFileDialog
GetPicture.Filter = PNGs(* .png),Bitmaps(* .bmp),GIFs(* .gif), JPEGs(* .jpg)| * .bmp; * .gif; *。jpg; * .png | PNGs(* .png)| * .png | Bitmaps(* .bmp)| * .bmp | GIFs(* .gif )| * .gif | JPEGs(* .jpg)| * .jpg
GetPicture.FilterIndex = 1
GetPicture.InitialDirectory = C:\
如果 GetPicture.ShowDialog = Windows.Forms.DialogResult.OK 然后
Dim SelectedPicture 作为 字符串 = GetPicture.FileName
Dim 图片 As Bitmap = 位图(SelectedPicture)
Dim cboard As Object = Clipboard.GetData(System.Windows.Forms.DataFormats.Text)
Clipboard.SetImage(Picture)
Dim PictureFormat As DataFormats.Format = DataFormats.GetFormat(DataFormats.Bitmap)
If RichTextBoxPrintCtrl1.CanPaste(PictureFormat)然后
RichTextBoxPrintCtrl1.Paste(PictureFormat)
End 如果
Clipboard.Clear()
Clipboard.SetText(cboard)
结束 如果
Catch ex 作为例外
结束 尝试
结束 Sub
私有 Sub Button_Click()
InsertPicture()
结束 Sub





如果此代码不是您所需要的,或者如果它与您现在使用的代码相同,那么这里是另一个选项此处。


Hi,

I've hit a snag with a Windows Forms application I'm building. The users want a control on a form into which they can paste formatted text and images. I've used a RichTextBox but the quality of image after pasting in is poor and very degraded compared to the original. It also doesn't allow for the image to be resized.

Is there any way I can correct these defects or am I simply taking the wrong approach? Is there an alternative I should have considered?

Thanks,

Tony.

解决方案

Hi Tony,

Here's the code for inserting images into RichTextBox, this will allow the user to resize the image but the image quality gets quite bad when resized (except when it's in the print preview dialogue).

Public Sub InsertPicture()
        Try
            Dim GetPicture As New OpenFileDialog
            GetPicture.Filter = "PNGs (*.png), Bitmaps (*.bmp), GIFs (*.gif), JPEGs (*.jpg)|*.bmp;*.gif;*.jpg;*.png|PNGs (*.png)|*.png|Bitmaps (*.bmp)|*.bmp|GIFs (*.gif)|*.gif|JPEGs (*.jpg)|*.jpg"
            GetPicture.FilterIndex = 1
            GetPicture.InitialDirectory = "C:\"
            If GetPicture.ShowDialog = Windows.Forms.DialogResult.OK Then
                Dim SelectedPicture As String = GetPicture.FileName
                Dim Picture As Bitmap = New Bitmap(SelectedPicture)
                Dim cboard As Object = Clipboard.GetData(System.Windows.Forms.DataFormats.Text)
                Clipboard.SetImage(Picture)
                Dim PictureFormat As DataFormats.Format = DataFormats.GetFormat(DataFormats.Bitmap)
                If RichTextBoxPrintCtrl1.CanPaste(PictureFormat) Then
                    RichTextBoxPrintCtrl1.Paste(PictureFormat)
                End If
                Clipboard.Clear()
                Clipboard.SetText(cboard)
            End If
        Catch ex As Exception
        End Try
    End Sub
    Private Sub Button_Click()
        InsertPicture()
    End Sub



If this code isn't what you need or if it's the same code you're using now then here's an alternative option here.


这篇关于VB.Net RichTextBox图像质量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆