| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2769 人关注过本帖
标题:[求助]再次求助关于图片放大,缩小问题
只看楼主 加入收藏
zhanghy1028
Rank: 1
等 级:新手上路
帖 子:108
专家分:0
注 册:2007-3-6
收藏
得分:0 

问题最终还是解决了,不过可能不是最优化,还请大家给看看,什么地方可能要做些改动.谢谢!!
private void btnBig_Click(object sender, EventArgs e)
{//放大图片

try
{
if (strName != "")
{
Bitmap MyBitmap = new Bitmap(this.pictureBox1.Image.Width*2, this.pictureBox1.Image.Height*2);
Graphics g = Graphics.FromImage(MyBitmap);
g.ScaleTransform(2, 2, System.Drawing.Drawing2D.MatrixOrder.Append);
g.DrawImage(this.pictureBox1.Image, 0, 0);
g.Save();
this.pictureBox1.Image = MyBitmap;


this.pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
this.panel1.AutoScroll = true;
this.panel1.Refresh();
this.pictureBox1.Refresh();
}
else
{
MessageBox.Show("请先选择图片", "信息提示!", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
catch (Exception Err)
{
MessageBox.Show(Err.Message);
}
}

private void btnSmall_Click(object sender, EventArgs e)
{//缩小图片
try
{
if (strName != "")
{
Bitmap MyBitmap = new Bitmap(this.pictureBox1.Image.Width/2, this.pictureBox1.Image.Height/2);
Graphics g = Graphics.FromImage(MyBitmap);
g.ScaleTransform(0.5f, 0.5f, System.Drawing.Drawing2D.MatrixOrder.Append);
g.DrawImage(this.pictureBox1.Image, 0, 0);
g.Save();
this.pictureBox1.Image = MyBitmap;

this.panel1.AutoScroll = false;
this.panel1.Refresh();
this.pictureBox1.Refresh();

}
else
{
MessageBox.Show("请先选择图片","信息提示!",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
catch (Exception Err)
{
MessageBox.Show(Err.Message);
}
}

private void btnCir_Click(object sender, EventArgs e)
{//顺时针旋转
try
{
if (strName != "")
{
this.pictureBox1.Image.RotateFlip(RotateFlipType.Rotate90FlipNone);
int i = this.pictureBox1.Height;
this.pictureBox1.Height = this.pictureBox1.Width;
this.pictureBox1.Width = i;
this.pictureBox1.Refresh();
}
else
{
MessageBox.Show("请先选择图片", "信息提示!", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
catch (Exception Err)
{
MessageBox.Show(Err.Message);
}
}

private void button1_Click(object sender, EventArgs e)
{//逆时针旋转
try
{
if (strName != "")
{
this.pictureBox1.Image.RotateFlip(RotateFlipType.Rotate90FlipXY);
int i = this.pictureBox1.Height;
this.pictureBox1.Height = this.pictureBox1.Width;
this.pictureBox1.Width = i;
this.pictureBox1.Refresh();
}
else
{
MessageBox.Show("请先选择图片", "信息提示!", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
catch (Exception Err)
{
MessageBox.Show(Err.Message);
}
}

private void btnZC_Click(object sender, EventArgs e)
{//正常显示
try
{
if (strName != "")
{
Bitmap MyBit = new Bitmap(strName);
Graphics g = Graphics.FromImage(MyBit);
g.DrawImage(MyBit, 0, 0);
g.Save();
this.pictureBox1.Image = MyBit;
this.pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
this.panel1.AutoScroll =true;
this.pictureBox1.Refresh();
}
else
{
MessageBox.Show("请先选择图片", "信息提示!", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
catch (Exception Err)
{
MessageBox.Show(Err.Message);
}
}

private void button2_Click(object sender, EventArgs e)
{//浏览图片
OpenFileDialog open = new OpenFileDialog();
open.Filter = "(*.jpg;*.bmp)|*.jpg;*.bmp|"+"(*.bmp)|*.bmp";
if (open.ShowDialog() == DialogResult.OK)
{
strName = open.FileName;
Bitmap bt = new Bitmap(strName);
this.pictureBox1.Image = bt;
this.pictureBox1.Refresh();
}
}

2007-03-23 08:59
zyslbj
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2007-3-23
收藏
得分:0 

好象用Panel也可以

2007-03-23 19:56
快速回复:[求助]再次求助关于图片放大,缩小问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.028235 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved