请问在C#中怎么设置一个图片按照指定的大小显示阿? this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 System.Drawing.Image img;img = new System.Drawing.Image.FromFile(文件名);img.Hight = xx;img.Width = xx;pictureBox1.Image = img; 楼上的方法好象不行吧无法对属性或索引器“System.Drawing.Image.Width”赋值 -- 它是只读的 try: Image img=Image.FromFile(@"g:\图片\ffx203.jpg"); Bitmap bmp=new Bitmap(img,150,150); bmp.Save(@"c:\123.jpg") 楼主:读一下MSDN下关于picturebox类的说明比什么都强! this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;System.Drawing.Image img;img = new System.Drawing.Image.FromFile(文件名);img.Hight = xx;img.Width = xx;pictureBox1.Image = img; 我做了个函数://*****************生成固定大小的缩略图*********************** public string ToThumbnailImages(string nCompRootUrl,string sourceImagePath,int thumbnailImageWidth,int thumbnailImageHeight) { htmimes[".gif"]="image/gif"; htmimes[".jpe"]="image/jpeg"; htmimes[".jpeg"]="image/jpeg"; htmimes[".jpg"]="image/jpeg"; htmimes[".png"]="image/png"; htmimes[".tif"]="image/tiff"; htmimes[".tiff"]="image/tiff"; htmimes[".bmp"]="image/bmp"; string SourceImagePath = sourceImagePath; int ThumbnailImageWidth = thumbnailImageWidth; int ThumbnailImageHeight=thumbnailImageHeight; string sExt = SourceImagePath.Substring(SourceImagePath.LastIndexOf(".")).ToLower(); string sSourceImageName = SourceImagePath.Substring(0,SourceImagePath.LastIndexOf(".")).ToLower(); string sThumbnailImagePath=sSourceImageName+"_little"+sExt; if(SourceImagePath.ToString()==System.String.Empty) throw new NullReferenceException("SourceImagePath is null!"); if(!CheckValidExt(sExt)) { throw new ArgumentException("原图片文件格式不正确,支持的格式有[ "+ AllowExt +" ]","SourceImagePath"); } //从 原图片 创建 Image 对象 System.Drawing.Image image = System.Drawing.Image.FromFile(HttpContext.Current.Server.MapPath(SourceImagePath)); int num = ((ThumbnailImageWidth / 4) * 3); int width = image.Width; int height = image.Height; //用指定的大小和格式初始化 Bitmap 类的新实例 //Bitmap bitmap = new Bitmap(ThumbnailImageWidth, num, PixelFormat.Format32bppArgb); Bitmap bitmap = new Bitmap(image,ThumbnailImageWidth,ThumbnailImageHeight); //从指定的 Image 对象创建新 Graphics 对象 Graphics graphics = Graphics.FromImage(bitmap); //清除整个绘图面并以透明背景色填充 graphics.Clear(Color.Transparent); //在指定位置并且按指定大小绘制 原图片 对象 //graphics.DrawImage(image, new Rectangle(0, 0, ThumbnailImageWidth, num)); graphics.DrawImage(image, new Rectangle(0,0,ThumbnailImageWidth,ThumbnailImageHeight)); image.Dispose(); try { //将此 原图片 以指定格式并用指定的编解码参数保存到指定文件 //string savepath = (ThumbnailImagePath==null?SourceImagePath:sThumbnailImagePath); string savepath = sThumbnailImagePath; SaveImage(bitmap,HttpContext.Current.Server.MapPath(savepath),GetCodecInfo((string)htmimes[sExt])); return savepath.ToString(); } catch(System.Exception e) { throw e; } finally { bitmap.Dispose(); graphics.Dispose(); } } void ThumbnailResize(string str_file, Size new_size) { Image src_image = Image.FromFile(str_file); Image dst_image = src_image.GetThumbnailImage(new_size.Width, new_size.Height, null, System.IntPtr.Zero); dst_image.Save("tn-" + str_file, System.Drawing.Imaging.ImageFormat.Jpeg); dst_image.Dispose(); src_image.Dispose(); } ThumbnailResize("aikido.jpg", new Size(655, 480)); 正则取图片问题?急 PrintPrivewDialog的"正在生成"对话框 MYQQ项目中的问题,在清空qq好友列表的时候出现错误! 求一个字符串分析解析的问题! 谁知道那里可以下载水晶报表10的汉化包? 各位..如何向ACCESS数据库中保存html代码? rdlc里的折线显示不出来,急!!!! winform的datagrid如何调整行的高度? 如何实现服务器推送技术 升级了,放分~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ datagrid高度的自动调节问题 一个关于MSDN例子的疑惑,求教大家
img = new System.Drawing.Image.FromFile(文件名);
img.Hight = xx;
img.Width = xx;pictureBox1.Image = img;
无法对属性或索引器“System.Drawing.Image.Width”赋值 -- 它是只读的
Bitmap bmp=new Bitmap(img,150,150);
bmp.Save(@"c:\123.jpg")
读一下MSDN下关于picturebox类的说明比什么都强!
System.Drawing.Image img;
img = new System.Drawing.Image.FromFile(文件名);
img.Hight = xx;
img.Width = xx;pictureBox1.Image = img;
//*****************生成固定大小的缩略图***********************
public string ToThumbnailImages(string nCompRootUrl,string sourceImagePath,int thumbnailImageWidth,int thumbnailImageHeight)
{
htmimes[".gif"]="image/gif";
htmimes[".jpe"]="image/jpeg";
htmimes[".jpeg"]="image/jpeg";
htmimes[".jpg"]="image/jpeg";
htmimes[".png"]="image/png";
htmimes[".tif"]="image/tiff";
htmimes[".tiff"]="image/tiff";
htmimes[".bmp"]="image/bmp";
string SourceImagePath = sourceImagePath;
int ThumbnailImageWidth = thumbnailImageWidth;
int ThumbnailImageHeight=thumbnailImageHeight;
string sExt = SourceImagePath.Substring(SourceImagePath.LastIndexOf(".")).ToLower();
string sSourceImageName = SourceImagePath.Substring(0,SourceImagePath.LastIndexOf(".")).ToLower();
string sThumbnailImagePath=sSourceImageName+"_little"+sExt;
if(SourceImagePath.ToString()==System.String.Empty) throw new NullReferenceException("SourceImagePath is null!");
if(!CheckValidExt(sExt))
{
throw new ArgumentException("原图片文件格式不正确,支持的格式有[ "+ AllowExt +" ]","SourceImagePath");
}
//从 原图片 创建 Image 对象
System.Drawing.Image image = System.Drawing.Image.FromFile(HttpContext.Current.Server.MapPath(SourceImagePath));
int num = ((ThumbnailImageWidth / 4) * 3);
int width = image.Width;
int height = image.Height;
//用指定的大小和格式初始化 Bitmap 类的新实例
//Bitmap bitmap = new Bitmap(ThumbnailImageWidth, num, PixelFormat.Format32bppArgb);
Bitmap bitmap = new Bitmap(image,ThumbnailImageWidth,ThumbnailImageHeight);
//从指定的 Image 对象创建新 Graphics 对象
Graphics graphics = Graphics.FromImage(bitmap);
//清除整个绘图面并以透明背景色填充
graphics.Clear(Color.Transparent);
//在指定位置并且按指定大小绘制 原图片 对象
//graphics.DrawImage(image, new Rectangle(0, 0, ThumbnailImageWidth, num));
graphics.DrawImage(image, new Rectangle(0,0,ThumbnailImageWidth,ThumbnailImageHeight));
image.Dispose();
try
{
//将此 原图片 以指定格式并用指定的编解码参数保存到指定文件
//string savepath = (ThumbnailImagePath==null?SourceImagePath:sThumbnailImagePath);
string savepath = sThumbnailImagePath;
SaveImage(bitmap,HttpContext.Current.Server.MapPath(savepath),GetCodecInfo((string)htmimes[sExt]));
return savepath.ToString();
}
catch(System.Exception e)
{
throw e;
}
finally
{
bitmap.Dispose();
graphics.Dispose();
}
}
{
Image src_image = Image.FromFile(str_file);
Image dst_image = src_image.GetThumbnailImage(new_size.Width,
new_size.Height, null, System.IntPtr.Zero);
dst_image.Save("tn-" + str_file,
System.Drawing.Imaging.ImageFormat.Jpeg);
dst_image.Dispose();
src_image.Dispose();
} ThumbnailResize("aikido.jpg", new Size(655, 480));