如何在pictureedit上最小化或调整supertooltip上的图像大小

时间:2017-01-06 06:14:50

标签: vb.net visual-studio-2012 devexpress

我的问题是当我将光标指向图片时,他们是带图像的supertooltip。但supertooltip内的图像太大了。如何以编程方式调整大小。

Public com As New MySql.Data.MySqlClient.MySqlCommand
Public da As New MySql.Data.MySqlClient.MySqlDataAdapter
Public dr As MySql.Data.MySqlClient.MySqlDataReader
Public ds As DataSet

Dim confirm As String

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  con.Close()
  con.Open()
  confirm = "select PPhoto From user_tbl"
  dr = com.ExecuteReader

  While dr.Read
    BarEditItem10.EditValue = Image.FromFile(pathfrm.PathPhoto.Text & dr.GetString("PPhoto"))
    Dim resImage As Image = Image.FromFile(pathfrm.PathPhoto.Text & dr.GetString("PPhoto"))
    Dim sTooltip2 As SuperToolTip = New SuperToolTip
    ' Create an object to initialize the SuperToolTip.
    Dim args As SuperToolTipSetupArgs = New SuperToolTipSetupArgs
    args.Title.Text = "Profile Picture"
    args.Contents.Text = "This is a Profile Picture"
    args.Contents.Image = resImage
    sTooltip2.Setup(args)
    BarEditItem10.SuperTip = sTooltip2
  End While
  con.Close()
End sub

First Image

当我将光标指向图片时(第二张图片)

Second Image

1 个答案:

答案 0 :(得分:0)

我建议在将图像分配给SuperToolTip之前重新调整图像大小。我在我的Previewing Images in a SuperToolTip博客文章中详细说明了如何执行此操作。

基本上我只是使用静态助手类来重新调整图像大小:

static internal Image ScaleThumbnailImage(Image ImageToScale, int MaxWidth, int MaxHeight)
{
    double ratioX = (double)MaxWidth / ImageToScale.Width;
    double ratioY = (double)MaxHeight / ImageToScale.Height;
    double ratio = Math.Min(ratioX, ratioY);

    int newWidth = (int)(ImageToScale.Width * ratio);
    int newHeight = (int)(ImageToScale.Height * ratio);

    Image newImage = new Bitmap(newWidth, newHeight);
    Graphics.FromImage(newImage).DrawImage(ImageToScale, 0, 0, newWidth, newHeight);

    return newImage; 
} 

这是在ToolTipController的GetActiveObjectInfo事​​件处理程序中完成的:

private void toolTipController1_GetActiveObjectInfo(object sender, DevExpress.Utils.ToolTipControllerGetActiveObjectInfoEventArgs e)
{

Image MyImage = Image.FromFile("C:\\your_file_here.jpg");

ToolTipControlInfo toolTipInfo = null;
SuperToolTip toolTip = new SuperToolTip();

toolTipInfo = new ToolTipControlInfo(Guid.NewGuid(), "My Image");
ToolTipItem item1 = new ToolTipItem();

item1.Image = ScaleThumbnailImage(MyImage, 640, 480);

toolTip.Items.Add(item1);

toolTipInfo.SuperTip = toolTip;
e.Info = toolTipInfo;
}