How to resize image if the image is bigger than Textbox.But it not increase scale if smaller

眉间皱痕 提交于 2019-12-13 14:14:00

问题


I created RDLC report layouts by using Visual Studio Report Designer.

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.

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.

What should I do if I need to

1.Centered image

2.Fit to textbox if image is bigger than textbox.

3.Original size if image is smaller that textbox.


回答1:


If you're using the same sizes of the tutorial you could try and set the Sizing property by using the following expression:

=IIF(Round((3.5-System.Drawing.Image.FromStream(new System.IO.MemoryStream(CType(Fields!LargePhoto.Value,Byte()))).Width
/96)/2,2)>0, "Clip", "Fit")



回答2:


I can resolved this problem by created two image control.

First image control -It was set sizing "Fit"

Second image control- It was set sizing "Clip" and used Chris Hays 's method for centered image.

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 is dpi

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 is widht of my textbox.

And Set Visibility of Second Image by the other hand.



来源:https://stackoverflow.com/questions/33491334/how-to-resize-image-if-the-image-is-bigger-than-textbox-but-it-not-increase-scal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!