请教为什么图片会粘不过去呢?以下是一些关键的代码
Bitmap bitmap = null; //按截图区域生成Bitmap
Image thumbImg = null; //被截图
Image test = null;
Graphics gps = null; //存绘图对象
bitmap = new System.Drawing.Bitmap(Convert.ToInt32(maxVal), Convert.ToInt32(maxVal));
thumbImg = System.Drawing.Image.FromFile(System.Web.HttpContext.Current.Server.MapPath(imgUrl));
System.Drawing.Rectangle rl = new System.Drawing.Rectangle(Convert.ToInt32(pointX), Convert.ToInt32(pointY), Convert.ToInt32(maxVal), Convert.ToInt32(maxVal)); //得到截图矩形
gps = System.Drawing.Graphics.FromImage(bitmap);
gps.DrawImage(thumbImg, 0, 0, rl, System.Drawing.GraphicsUnit.Pixel);
需要加上 gps.DrawImage(thumbImg, 0, 0, width, height);
Bitmap bitmap = null; //按截图区域生成Bitmap
Image thumbImg = null; //被截图
Image test = null;
Graphics gps = null; //存绘图对象
bitmap = new System.Drawing.Bitmap(Convert.ToInt32(maxVal), Convert.ToInt32(maxVal));
thumbImg = System.Drawing.Image.FromFile(System.Web.HttpContext.Current.Server.MapPath(imgUrl));
System.Drawing.Rectangle rl = new System.Drawing.Rectangle(Convert.ToInt32(pointX), Convert.ToInt32(pointY), Convert.ToInt32(maxVal), Convert.ToInt32(maxVal)); //得到截图矩形
gps = System.Drawing.Graphics.FromImage(bitmap);
gps.DrawImage(thumbImg, 0, 0, width, height);
gps.DrawImage(thumbImg, 0, 0, rl, System.Drawing.GraphicsUnit.Pixel);
我加上您说的那个之后就没有了截图的功能效果,在 Bitmap 那边就规定好了这个画布的大小了,后面还需要再规定大小吗?
@Yang小杨: 我们在项目中实际使用的代码
using (var originImage = Image.FromFile(imagePhysicalPath))
{
using (var newImage = new Bitmap(width, height))
{
using (var graphic = Graphics.FromImage(newImage))
{
graphic.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
graphic.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
graphic.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
graphic.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
graphic.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
graphic.DrawImage(originImage, 0, 0, w, h);
graphic.DrawImage(originImage, new Rectangle(0, 0, width, height), x, y, w, h, GraphicsUnit.Pixel);
}
}
}
@dudu: 请问这个是压缩图片还是截图?类似QQ头像的那种
@Yang小杨: 截取图片作为头像
@dudu: 谢谢啦
@dudu: 请问一下,用户上传的头像存储的形式是什么?在服务器上建一个文件夹存放吗?
@Yang小杨: 我们是存储到阿里云OSS与腾讯云COS