用visual studio2010做的简单开发 新手一枚,做了一个简单的打开按钮,打开了一幅图像,想在加载图片的picturebox上,自由缩放图片,不知道怎样写代码,要先定义图片的高和宽么? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Image img = Image.FromFile(@"c:\a.jpg");Bitmap bmp = new Bitmap(img, 100, 100); //缩放后的宽度为100,高度为80,你根据实际缩放来写pictureBox1.Image = bmp; Image img = Image.FromFile(@"c:\a.jpg");Bitmap bmp = new Bitmap(img, 100, 80); //缩放后的宽度为100,高度为80,你根据实际缩放来写img.Dispose();pictureBox1.Image = bmp; private void toolStripLabel3_Click(object sender, EventArgs e) { Image img = Image.FromFile(openFile.FileName); Bitmap bmp = new Bitmap(img,Width*2,Height*2); img.Dispose(); pictureBox1.Image = bmp; }如果我是这样设计的控件代码,怎样才能每次点击都能放大到原来的2倍? 思路pictureBox1_Paint(){graphic = pictureBox1.CreateGraphic();Image img = Image.FromFile(path);graphic.DrawImage(img, 图片的尺寸x2);} 每次放大到原来的2倍可以定义一个成员变量double 倍数点button 倍数x2上面graphic.DrawImage(img, 图片的尺寸x2);=>graphic.DrawImage(img, 图片的尺寸x倍数); 因为我打开图片的是用一个按钮打开的,在按钮定义外部写了 OpenFileDialog openFile = new OpenFileDialog();而这个是按钮的打开代码string path = openFile.FileName; Image image = Image.FromFile(path); this.pictureBox1.Image = image;这些按钮是私有的,所以不能访问他们定义的image另一方面,我为了访问刚才打开的图片,就重新定义打开图片的那些信息: private void toolStripLabel3_Click(object sender, EventArgs e) { Image img = Image.FromFile(openFile.FileName); Bitmap bmp = new Bitmap(img,Width*2,Height*2); img.Dispose(); pictureBox1.Image = bmp; }发现每一次点击这个按钮,他都重新加载刚才打开的图片,所以只能对打开图片做一次的放大;我想打开这张图片后,点击一个按钮就可以放大,不会出现以上的问题。 http://developer.51cto.com/art/200909/148623.htm DataGridView有效性检查的控制 multimedia timer与queue Timer的区别 lambda.Compile(); //抛出一个异常 Lambda 参数不在作用域内 如何给系统打包 用webBrower,TabContol做浏览器的问题 C#4.0入门 第二章 任务并行库—第三页 性能的差异 保存DataGrid的数据到数据源 各位老大,关于连接sqlserver的问题,严重了 如何调用EXE文件 请问如何使mdi的子窗口大小随父窗口变化 求解脱 怎么获取ie弹出的脚本内容,并把脚本上的表单提交
pictureBox1.Image = bmp;
Bitmap bmp = new Bitmap(img, 100, 80); //缩放后的宽度为100,高度为80,你根据实际缩放来写
img.Dispose();
pictureBox1.Image = bmp;
{
Image img = Image.FromFile(openFile.FileName);
Bitmap bmp = new Bitmap(img,Width*2,Height*2);
img.Dispose();
pictureBox1.Image = bmp;
}
如果我是这样设计的控件代码,怎样才能每次点击都能放大到原来的2倍?
pictureBox1_Paint()
{
graphic = pictureBox1.CreateGraphic();
Image img = Image.FromFile(path);
graphic.DrawImage(img, 图片的尺寸x2);
}
double 倍数
点button 倍数x2
上面graphic.DrawImage(img, 图片的尺寸x2);
=>
graphic.DrawImage(img, 图片的尺寸x倍数);
Image image = Image.FromFile(path);
this.pictureBox1.Image = image;这些按钮是私有的,所以不能访问他们定义的image
另一方面,我为了访问刚才打开的图片,就重新定义打开图片的那些信息:
private void toolStripLabel3_Click(object sender, EventArgs e)
{
Image img = Image.FromFile(openFile.FileName);
Bitmap bmp = new Bitmap(img,Width*2,Height*2);
img.Dispose();
pictureBox1.Image = bmp;
}
发现每一次点击这个按钮,他都重新加载刚才打开的图片,所以只能对打开图片做一次的放大;
我想打开这张图片后,点击一个按钮就可以放大,不会出现以上的问题。