上传图片 印上了一句话 ,在保存, 大小比原图大了4倍,且用photoshop打不开(找到不知名的或无效的JPEG标志符类型),但是可以在网页上显示。代码如下: Graphics g=null;
Bitmap bigimg=null;
System.Drawing.Image thumimg=null;
System.Drawing.Image upimage=null;
int width,height,newwidth,newheight;
upimage= System.Drawing.Image.FromStream(UpLoadTextBox.PostedFile.InputStream);
width = upimage.Width;
height = upimage.Height;
newwidth=250;
newheight=190; thumimg = upimage.GetThumbnailImage(newwidth,newheight,null,IntPtr.Zero);
bigimg=new Bitmap(upimage);
g=Graphics.FromImage(bigimg);
Font f = new Font("Arial Black", 18);
Brush b= new SolidBrush(Color.Gray);
String s= "YYHOU.COM"; g.DrawString(s, f, b,width-170,height-37);
thumimg.Save(FullSmallPath);
bigimg.Save(FullBigPath);
thumimg.Dispose();
upimage.Dispose();
bigimg.Dispose(); 另外压缩后 失真很厉害!是不是图像变大 是因为g=Graphics.FromImage(bigimg); 直接存的话 就不会变了。怎么 搞了???谢谢!!!
Bitmap bigimg=null;
System.Drawing.Image thumimg=null;
System.Drawing.Image upimage=null;
int width,height,newwidth,newheight;
upimage= System.Drawing.Image.FromStream(UpLoadTextBox.PostedFile.InputStream);
width = upimage.Width;
height = upimage.Height;
newwidth=250;
newheight=190; thumimg = upimage.GetThumbnailImage(newwidth,newheight,null,IntPtr.Zero);
bigimg=new Bitmap(upimage);
g=Graphics.FromImage(bigimg);
Font f = new Font("Arial Black", 18);
Brush b= new SolidBrush(Color.Gray);
String s= "YYHOU.COM"; g.DrawString(s, f, b,width-170,height-37);
thumimg.Save(FullSmallPath);
bigimg.Save(FullBigPath);
thumimg.Dispose();
upimage.Dispose();
bigimg.Dispose(); 另外压缩后 失真很厉害!是不是图像变大 是因为g=Graphics.FromImage(bigimg); 直接存的话 就不会变了。怎么 搞了???谢谢!!!
{
destRect.Width = dest.Width;
destRect.Height = dest.Height;
using (Graphics g = Graphics.FromImage(dest))
{
System.Drawing.Brush b = new SolidBrush(System.Drawing.Color.White);
g.FillRectangle(b, destRect);
srcRect.Width = src.Width;
srcRect.Height = src.Height;
float sourceAspect = (float)src.Width / (float)src.Height;
float destAspect = (float)dest.Width / (float)dest.Height;
if (sourceAspect > destAspect)
{
// 宽度大于高度时,保持宽度不变,按照比例增加高度(请注意:示例程序文件中的程序员注释使用的是英文,本文中将其译为中文是为了便于参考)
destRect.Width = dest.Width;
destRect.Height = (int)((float)dest.Width / sourceAspect);
destRect.X = 0;
destRect.Y = (dest.Height - destRect.Height) / 2;
}
else
{
// 高度大于宽度时,保持高度不变,按照比例增加宽度
destRect.Height = dest.Height;
destRect.Width = (int)((float)dest.Height * sourceAspect);
destRect.X = (dest.Width - destRect.Width) / 2;
destRect.Y = 0;
}
g.InterpolationMode=InterpolationMode.HighQualityBicubic;////这里,高质量的存储,存的图片会更好一点
g.DrawImage(src, destRect, srcRect, System.Drawing.GraphicsUnit.Pixel);
}
}