asp.net – .net Drawing.Graphics.FromImage()返回空白的黑色图
发布时间:2020-12-16 06:57:28 所属栏目:asp.Net 来源:网络整理
导读:我正在尝试在asp.net中重新调整上传的jpeg 所以我去: Image original = Image.FromStream(myPostedFile.InputStream);int w=original.Width,h=original.Height;using(Graphics g = Graphics.FromImage(original)){ g.ScaleTransform(0.5f,0.5f); ... // e.g
|
我正在尝试在asp.net中重新调整上传的jpeg
所以我去: Image original = Image.FromStream(myPostedFile.InputStream);
int w=original.Width,h=original.Height;
using(Graphics g = Graphics.FromImage(original))
{
g.ScaleTransform(0.5f,0.5f); ... // e.g.
using (Bitmap done = new Bitmap(w,h,g))
{
done.Save( Server.MapPath(saveas),ImageFormat.Jpeg );
//saves blank black,though with correct width and height
}
}
这节省了处女黑色jpeg我给它的任何文件. Image original = Image.FromStream(myPostedFile.InputStream);
using (Bitmap done = new Bitmap(original))
{
done.Save( Server.MapPath(saveas),ImageFormat.Jpeg );
}
我必须用g制作一些魔法吗? UPD: Image original = Image.FromStream(fstream);
int w=original.Width,h=original.Height;
using(Bitmap b = new Bitmap(original)) //also tried new Bitmap(w,h)
using (Graphics g = Graphics.FromImage(b))
{
g.DrawImage(original,w,h); //also tried g.DrawImage(b,h)
using (Bitmap done = new Bitmap(w,g))
{
done.Save( Server.MapPath(saveas),ImageFormat.Jpeg );
}
}
相同的故事 – 正确尺寸的纯黑色 解决方法
由于您没有使用inputStream读取的图像背景填充区域,因此只能获得空白图像.
您可以使用填充背景到调整大小的区域,而不是使用缩放图像. 看一下这个: Image img = Image.FromFile(Server.MapPath("a.png"));
int w = img.Width;
int h = img.Height;
//Create an empty bitmap with scaled size,here half
Bitmap bmp = new Bitmap(w / 2,h / 2);
//Create graphics object to draw
Graphics g = Graphics.FromImage(bmp);
//You can also use SmoothingMode,CompositingMode and CompositingQuality
//of Graphics object to preserve saving options for new image.
//Create drawing area with a rectangle
Rectangle drect = new Rectangle(0,bmp.Width,bmp.Height);
//Draw image into your rectangle area
g.DrawImage(img,drect);
//Save your new image
bmp.Save(Server.MapPath("a2.jpg"),ImageFormat.Jpeg);
希望这可以帮助迈拉 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- ASP.NET Core 3.1 WebApi+JWT+Swagger+EntityFrameworkCore
- 我如何设置我的ASP.NET项目来查找我的文件?
- asp.net – 自动刷新浏览器缓存
- asp.net-mvc – 如何在ASP.NET MVC视图中对HTML列表项进行分
- asp.net – Azure中的IP安全性和始终开启设置
- asp.net-mvc – 使用路由操作URL
- asp.net-mvc-3 – mvc razor editortemplate中的脚本
- asp.net – 如何在asp中使用会话变量使用c#
- ASP.NET 谨用 async/await
- 将ASP.NET应用程序部署到远程服务器
推荐文章
站长推荐
- 绘制图表到ASP.NET MVC 4(Razor,C#)网站
- asp.net – 多态 – 覆盖和重载
- asp.net-mvc – 大型Web应用程序中的Windows Wor
- ABP(现代ASP.NET样板开发框架)系列之二、ABP入门
- asp.net-mvc – 哪种类型的缓存适合在Umbraco项目
- asp.net-mvc – 在Mono 2.4上使用Microsoft Data
- asp.net – 在Web api控制器中手动验证模型
- ASP.Net错误 – 类型与控件类型不兼容
- asp.net-core – uri查询参数中的asp.net核心JWT
- 如何从本地asp.net 4.0 Web应用程序发送支持图像
热点阅读
