找回密码
 立即注册

QQ登录

只需一步,快速开始

mosquito

初级会员

24

主题

138

帖子

328

积分

初级会员

积分
328
mosquito
初级会员   /  发表于:2016-3-3 10:26  /   查看:7434  /  回复:12
您好:
     我想用一个按钮控制imageViewer里图像的大小是修改imageViewer.ScaleFactor的值吗?
但是为什么我给这个值赋值是显示该属性是只读属性的错误提示呢?
因为我扫描的tif图片在imageviewer里默认显示很大,我想扫描后的图片能按一定比例缩放到屏幕可以看完整图,应该怎么实现?
帮我解答下吧,谢谢了
我扫描后的图片到imageviewer里显示如下:

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x

12 个回复

倒序浏览
gw0506
超级版主   /  发表于:2016-3-3 17:01:00
沙发
不会呀,这个值可以设置。
你用的什么平台的LeadTools,哪个版本?
V19下,这个属性可以设置,示例代码:
  1. using Leadtools.Help;
  2. using Leadtools.Windows.Controls;
  3. public void ImageViewer_ScaleFactor(ImageViewer viewer)
  4. {
  5.    viewer.ScaleFactor = viewer.ScaleFactor * 0.9f;
  6.    string s = string.Format("HorizontalScaleFactor {0}, VerticalScaleFactor {1}", viewer.CurrentXScaleFactor, viewer.CurrentYScaleFactor);
  7.    MessageBox.Show(s);
  8. }
复制代码
回复 使用道具 举报
mosquito
初级会员   /  发表于:2016-3-3 17:04:00
板凳
我的是leadtools19
回复 使用道具 举报
mosquito
初级会员   /  发表于:2016-3-3 17:07:00
地板

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复 使用道具 举报
mosquito
初级会员   /  发表于:2016-3-3 17:11:00
5#
我写的是c#的windows窗体程序
回复 使用道具 举报
gw0506
超级版主   /  发表于:2016-3-3 17:50:00
6#
用Zoom方法就可以了,例如:
  1. viewer.Zoom(ControlSizeMode.None, viewer.ScaleFactor * 2.0, viewer.DefaultZoomOrigin);
复制代码
回复 使用道具 举报
mosquito
初级会员   /  发表于:2016-3-4 08:59:00
7#
那我想扫描的图片默认能看完整图的话这个缩放比例应该怎么把控,得我自己试这个viewer.ScaleFactor * 2.0  数值吗?还是有参考的参数,我扫描后给imageviewer赋值的时候图片太大了如我刚开始发的图片,还有一个问题如果我想让这个图片位于我的程序面板的中央应该怎么设置呀?麻烦您解答下,谢谢了
回复 使用道具 举报
gw0506
超级版主   /  发表于:2016-3-4 14:10:00
8#
这个你的尝试了,多试几次,找个合适的参数。

居中的事情,你可参考如下代码:
  1. using Leadtools.WinForms;
  2. using Leadtools;
  3. using Leadtools.Codecs;
  4. using Leadtools.ImageProcessing.Color;
  5. using Leadtools.Drawing;
  6. void ZoomAndCenter(RasterImageViewer viewer, double scaleFactor)
  7. {
  8.    // Minimum and maximum scale factors allowed (change if you have to)
  9.    const double minimumScaleFactor = 0.05;
  10.    const double maximumScaleFactor = 11;
  11.    // Normalize the scale factor based on min and max
  12.    scaleFactor = Math.Max(minimumScaleFactor, Math.Min(maximumScaleFactor, scaleFactor));
  13.    // Check if we need to change the scale factor for the viewer
  14.    if(viewer.ScaleFactor != scaleFactor)
  15.    {
  16.       // Get the current center in logical units
  17.       // We will use this point later to re-center the viewer
  18.       // Get what you see in physical coordinates
  19.       Rectangle rc = Rectangle.Intersect(viewer.PhysicalViewRectangle, viewer.ClientRectangle);
  20.       // Get the center of what you see in physical coordinates
  21.       PointF center = new PointF(rc.Left + rc.Width / 2, rc.Top + rc.Height / 2);
  22.       Transformer t = new Transformer(viewer.Transform);
  23.       // Get the center of what you see in logical coordinates
  24.       center = t.PointToLogical(center);
  25.       // Set the new scale factor
  26.       viewer.ScaleFactor = scaleFactor;
  27.       // Bring the original center into the view center
  28.       t = new Transformer(viewer.Transform);
  29.       // Get the center of what you saw before the zoom in physical coordinates
  30.       center = t.PointToPhysical(center);
  31.       // Bring the old center into the center of the view
  32.       viewer.CenterAtPoint(Point.Round(center));
  33.    }
  34. }
复制代码
回复 使用道具 举报
mosquito
初级会员   /  发表于:2016-3-4 15:05:00
9#
好的辛苦您啦,我试下
回复 使用道具 举报
gw0506
超级版主   /  发表于:2016-3-4 15:46:00
10#
不辛苦,别那么客气。
这些代码都是文档里现成的,其实你也可以拿到。
回复 使用道具 举报
12下一页
您需要登录后才可以回帖 登录 | 立即注册
返回顶部