一下是第一题的答案~我是用winform做的
Stream myStream;
try
{
openFileDialog1.InitialDirectory ="e:\\JPGE";
//定义打开图片的初始路径
this.openFileDialog1.Filter="*.bmp|*.bmp|*.psd|*.psd|*.tif|*.tif";
if(openFileDialog1.ShowDialog() == DialogResult.OK)
{
if((myStream = openFileDialog1.OpenFile())!= null)
{
myStream.Close();
}
System.Drawing.Bitmap bp=new Bitmap(this.openFileDialog1.FileName);
//创建图片对象1
height=bp.PhysicalDimension.Height;
weight=bp.PhysicalDimension.Width;//获取图片的高度和宽度
height=Convert.ToInt32(height*0.6);
weight=Convert.ToInt32(weight*0.6);//将图片的大小缩进60%
count=this.openFileDialog1.FileName.Length;
count=count-3;
str=this.openFileDialog1.FileName.Remove(count,3);//为要转化的图片定义后缀名
Bitmap newbp=new Bitmap(bp,Convert.ToInt32(weight),Convert.ToInt32(height));//创建图片对象2,并定义对象2的大小
newbp.Save(str+"jpg",System.Drawing.Imaging.ImageFormat.Jpeg);
MessageBox.Show("文件转换成功..");
}
else
{
MessageBox.Show("您没有选择文件" );
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}