在运行时选择图像并能够调整图像大小(转换) [英] Image Select at Runtime and able to Re sizing the image (Transform)

查看:60
本文介绍了在运行时选择图像并能够调整图像大小(转换)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友,
我正在使用C#使用Windows应用程序,我有一个疑问让我解释一下,

说明:
我在Windows应用程序中有一个面板和一个按钮控件,当我单击按钮"时,添加了面板的运行时图像(不使用图片框控件),当我单击该图像的鼠标时,我需要选择该图像运行时,并且同时能够调整大小(如变形"),以使图像的右,左,上,下,左,左,右向八个.

请给我一些想法,我该怎么做.我尝试了最近20天,但仍然没有实现.

Dear friends,
I am using windows Application using C#, i have one doubt let i explain,

Explain :
I have one panel and one button control in windows application, When i click the Button I added the image of run time (Without using picture box control) of the panel, I need to select that image runtime when i click the mouse of that image, and that same time it able to re size (like Transform) that image eight right,left,top,bottom, side-left, side-right.

Please give me the Ideas how i do that. I try that last 20 days, still i didn''t achieve.

推荐答案

调整图片大小的示例;

an Example to resize a picture;

public  static Image resizeImage(Image imgToResize, Size size)
        {
            int sourceWidth = imgToResize.Width;
            int sourceHeight = imgToResize.Height;

            float nPercent = 0;
            float nPercentW = 0;
            float nPercentH = 0;

            nPercentW = ((float)size.Width / (float)sourceWidth);
            nPercentH = ((float)size.Height / (float)sourceHeight);

            if (nPercentH < nPercentW)
                nPercent = nPercentH;
            else
                nPercent = nPercentW;

            int destWidth = (int)(sourceWidth * nPercent);
            int destHeight = (int)(sourceHeight * nPercent);

            Bitmap b = new Bitmap(destWidth, destHeight);
            Graphics g = Graphics.FromImage((Image)b);
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;

            g.DrawImage(imgToResize, 0, 0, destWidth, destHeight);
            g.Dispose();

            return (Image)b;
        }


这篇关于在运行时选择图像并能够调整图像大小(转换)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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