VS里可以修改图片大小吗

如题所述

可以。有很多方法,常见的,如果要把图片放到picturebox 或者label上,只要将该控件的大小设置成你预设的大小即可。
当然,visual studio 还提供专门的图片制作功能,可以精确到每一个显像点!
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-09-30
//参数分别为图片源文件,处理完图片存放目录,生成的图片宽,国片长,填充背景颜色,边框
public static void MakePic(string sourceImg, string toPath, int width, int height, string backColor, string borderColor)
{
System.Drawing.Image originalImage = System.Drawing.Image.FromFile(sourceImg);
int towidth = width;
int toheight = height;

int x = 0;
int y = 0;
int ow = originalImage.Width;
int oh = originalImage.Height;
string mode;

if (ow < towidth && oh < toheight)
{
towidth = ow;
toheight = oh;
}
else
{
if (originalImage.Width / originalImage.Height >= width / height)
{
mode = "W";
}
else
{
mode = "H";
}
switch (mode)
{
case "W"://指定宽,高按比例
toheight = originalImage.Height * width / originalImage.Width;
break;
case "H"://指定高,宽按比例
towidth = originalImage.Width * height / originalImage.Height;
break;
default:
break;
}
}

//新建一个bmp图片
System.Drawing.Image bitmap = new System.Drawing.Bitmap(width, height);

//新建一个画板
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap);
//设置高质量插值法
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;

//设置高质量,低速度呈现平滑程度
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

//清空画布并以指定颜色填充
g.Clear(ColorTranslator.FromHtml(backColor));

//在指定位置并且按指定大小绘制原图片的指定部分
int top = (height - toheight) / 2;
int left = (width - towidth) / 2;
g.DrawImage(originalImage, new System.Drawing.Rectangle(left, top, towidth, toheight),
new System.Drawing.Rectangle(x, y, ow, oh),
System.Drawing.GraphicsUnit.Pixel);

Pen pen = new Pen(ColorTranslator.FromHtml(borderColor));
g.DrawRectangle(pen, 0, 0, width - 1, height - 1);
try
{
//以jpg格式保存缩略图
bitmap.Save(toPath, System.Drawing.Imaging.ImageFormat.Jpeg);
}
catch (System.Exception e)
{
throw e;
}
finally
{
originalImage.Dispose();
bitmap.Dispose();
g.Dispose();
}
}
第2个回答  2010-09-30
如果你是指显示大小,我可以明确告诉你可以,如果你想改变图片本身,只要你够牛,你可以用vs自己做一个图片编辑器来改变图片