如果图像大于文本框,如何调整图像大小,但如果图像小于文本框,则不增加缩放比例 [英] How to resize image if the image is bigger than Textbox.But it not increase scale if smaller
问题描述
我使用Visual Studio报表设计器创建了RDLC报表布局.
I created RDLC report layouts by using Visual Studio Report Designer.
我需要在文本框上显示图像. 通过克里斯·海斯(Chris Hays)的方法. 但是此方法必须将大小设置为剪辑"
I need to display image on textbox. The image was set center align by Chris Hays 's method. But This method must set sizing to be "Clip"
所以有一个问题,因为从数据库获取的图像大于文本框.它会像下面一样被剪掉.
So It has a problem because when Image which it was getting from database is bigger than textbox. It would clipped like below.
我尝试在"Fit Proportional"模式下使用大小调整.它无法通过
I tried to use sizing with "Fit Proportional" Mode. It can't set centered image by Chris Hays 's method.
但是,如果我将尺寸调整与适合尺寸"配合使用.我可以忽略居中的图像.但是如果某些图像很小.它将失去质量.
But if I use sizing with "Fit to size". I can ignore centered image. But if some image is very small. It will lose quality.
如果需要我该怎么办
1.居中图片
2.如果图像大于文本框,则适合文本框.
3.原始尺寸(如果图像比文本框小).
3.Original size if image is smaller that textbox.
推荐答案
我可以通过创建两个图像控件来解决此问题.
I can resolved this problem by created two image control.
第一个图像控件-设置为"Fit"大小
第二个图像控制-设置了剪辑"的大小,并使用克里斯·海斯(Chris Hays)的方法对中图像.
两个图像控件都通过表达式设置了Visibility属性
Both two image controls was set Visibility property by expression
如果图像的宽度大于文本框,则将显示第一个图像控件,第二个将隐藏.
if a width of image is bigger than textbox , First image control will show and second will hide.
如果图像的宽度小于文本框,则将隐藏第一个图像控件,然后显示第二个图像.
if a width of image is smaller than textbox , First image control will hide and second will show.
我可以通过此代码获得图像的宽度
I can get a width of image by this code
=(System.Drawing.Image.FromStream(new System.IO.MemoryStream(CType(First(Fields!FILE_BINARY_DATA.Value, "My Table"),Byte()))).Width /96)
96 是dpi
从上面的表达式知道图像的宽度之后. 我将使用它来设置像这样的First Image的Visibility属性
After I known a width of image from above expression. I will use it for set Visibility Property of First Image like these
=iif((imgWidthInch.Value > 2.6 ),false,true)
2.6 是我的文本框.
另一方面,设置第二张图片的可见性".
And Set Visibility of Second Image by the other hand.
这篇关于如果图像大于文本框,如何调整图像大小,但如果图像小于文本框,则不增加缩放比例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!