asp.net上传头像在线裁减 由于工作需要,要让用户上传的头像可以按自己想要的区块进行裁减。该怎么做呢?帮帮忙! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 private void Page_Load(object sender, System.EventArgs e) { ImgReduceCutOut(100,120,"1.jpg","2.jpg"); } /// <summary> /// 缩小裁剪图片 /// </summary> /// <param name="int_Width">要缩小裁剪图片宽度</param> /// <param name="int_Height">要缩小裁剪图片长度</param> /// <param name="input_ImgUrl">要处理图片路径</param> /// <param name="out_ImgUrl">处理完毕图片路径</param> public void ImgReduceCutOut(int int_Width,int int_Height,string input_ImgUrl,string out_ImgUrl) { // ===上传标准图大小=== int int_Standard_Width=160; int int_Standard_Height=160; int Reduce_Width=0; // 缩小的宽度 int Reduce_Height=0; // 缩小的高度 int CutOut_Width=0; // 裁剪的宽度 int CutOut_Height=0; // 裁剪的高度 int level = 100; //缩略图的质量 1-100的范围 // ===获得缩小,裁剪大小=== if (int_Standard_Height*int_Width/int_Standard_Width>int_Height) { Reduce_Width=int_Width; Reduce_Height=int_Standard_Height*int_Width/int_Standard_Width; CutOut_Width=int_Width; CutOut_Height=int_Height; } else if (int_Standard_Height*int_Width/int_Standard_Width<int_Height) { Reduce_Width=int_Standard_Width*int_Height/int_Standard_Height; Reduce_Height=int_Height; CutOut_Width=int_Width; CutOut_Height=int_Height; } else { Reduce_Width=int_Width; Reduce_Height=int_Height; CutOut_Width=int_Width; CutOut_Height=int_Height; } // ===通过连接创建Image对象=== System.Drawing.Image oldimage = System.Drawing.Image.FromFile(Server.MapPath(input_ImgUrl)); // ===缩小图片=== System.Drawing.Image thumbnailImage = oldimage.GetThumbnailImage(Reduce_Width, Reduce_Height,new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero); Bitmap bm=new Bitmap(thumbnailImage); // ===处理JPG质量的函数=== ImageCodecInfo[] codecs=ImageCodecInfo.GetImageEncoders(); ImageCodecInfo ici=null; foreach(ImageCodecInfo codec in codecs) { if(codec.MimeType=="image/jpeg") ici=codec; } EncoderParameters ep=new EncoderParameters(); ep.Param[0]=new EncoderParameter(Encoder.Quality,(long)level); bm.Save(Server.MapPath("2.jpg"),ici,ep); // ===裁剪图片=== Rectangle cloneRect = new Rectangle(0, 0, CutOut_Width, CutOut_Height); PixelFormat format = bm.PixelFormat; Bitmap cloneBitmap = bm.Clone(cloneRect, format); // ===保存图片=== cloneBitmap.Save(Server.MapPath(out_ImgUrl),ici,ep); } public bool ThumbnailCallback() { return false; } http://hi.baidu.com/wyzwyzwyz/blog/item/fdaa7c252696546c35a80f6c.htmlhttp://kb.cnblogs.com/page/47074/2/ Jquery+ASP.NET 实现上传头像剪裁 看到上面的例子,他是直接赋图片给img src的要结合图片预览怎么做呢当选择图片时,图片可以显示在那快裁减的框然后进行裁减! 假设1.jpg就是原图像,在客户端将要裁剪的区域的左上角和右下角位置保存下来pt1和pt2,然后将图片完整上传到服务器,不要裁剪在调用时候直接如下<div style="background-image:url(1.jpg);width:200px;height:150px; background-position: 50px 50px;"></div>width是pt2.x-pt1.x绝对值height是pt2.y-pt1.y绝对值background-position:只用pt1.x和pt1.y就是这样子,大概 如果要缩放图像的话,这样修改下;<div style="width:200px;height:150px; overflow:hidden;" ><img src="1.jpg" style="width:300px;height:250px; position:relative; left:-50px;top:-50px" /></div> http://www.codesoso.com/code/Image-Corp-Scale-Control.aspx这个控件实现与.NET1.1环境中,作为一个ASP.NET控件,它可以允许用户在客户端上传一幅图像到服务器上,并在浏览器中直接对图像进行裁剪、缩放、修改成为一个web可用的图像。 阿捷 rdlc报表柱状图y轴的最大值确定 关于Lucene.Net的全文搜索 最简单的增删改查采用分布式缓存该怎么实现? 请教ASP.NET操作EXCEL的问题,第一次来,谢谢大家! datagrid 转excel如何在列名上面再加上表名!! 请教如何抓取ssl加密页面的内容,https://.. 求教:如何用下拉列表框动态绑定页面中字体的大小 高手指点下 请大伙帮我看看,问题出在哪里啊!头大了! 怎么样创建一个组件??? 原来可以运行的<object id=..>,现在运行不了了。 请求设计一个方法,在后台得到数字几,就在前台页面出现几颗星(图片) 博客开发
private void Page_Load(object sender, System.EventArgs e)
{
ImgReduceCutOut(100,120,"1.jpg","2.jpg");
}
/// <summary>
/// 缩小裁剪图片
/// </summary>
/// <param name="int_Width">要缩小裁剪图片宽度</param>
/// <param name="int_Height">要缩小裁剪图片长度</param>
/// <param name="input_ImgUrl">要处理图片路径</param>
/// <param name="out_ImgUrl">处理完毕图片路径</param>
public void ImgReduceCutOut(int int_Width,int int_Height,string input_ImgUrl,string out_ImgUrl)
{
// ===上传标准图大小===
int int_Standard_Width=160;
int int_Standard_Height=160; int Reduce_Width=0; // 缩小的宽度
int Reduce_Height=0; // 缩小的高度
int CutOut_Width=0; // 裁剪的宽度
int CutOut_Height=0; // 裁剪的高度
int level = 100; //缩略图的质量 1-100的范围
// ===获得缩小,裁剪大小===
if (int_Standard_Height*int_Width/int_Standard_Width>int_Height)
{
Reduce_Width=int_Width;
Reduce_Height=int_Standard_Height*int_Width/int_Standard_Width;
CutOut_Width=int_Width;
CutOut_Height=int_Height;
}
else if (int_Standard_Height*int_Width/int_Standard_Width<int_Height)
{
Reduce_Width=int_Standard_Width*int_Height/int_Standard_Height;
Reduce_Height=int_Height;
CutOut_Width=int_Width;
CutOut_Height=int_Height;
}
else
{
Reduce_Width=int_Width;
Reduce_Height=int_Height;
CutOut_Width=int_Width;
CutOut_Height=int_Height;
} // ===通过连接创建Image对象===
System.Drawing.Image oldimage = System.Drawing.Image.FromFile(Server.MapPath(input_ImgUrl)); // ===缩小图片===
System.Drawing.Image thumbnailImage = oldimage.GetThumbnailImage(Reduce_Width, Reduce_Height,new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero);
Bitmap bm=new Bitmap(thumbnailImage); // ===处理JPG质量的函数===
ImageCodecInfo[] codecs=ImageCodecInfo.GetImageEncoders();
ImageCodecInfo ici=null;
foreach(ImageCodecInfo codec in codecs)
{
if(codec.MimeType=="image/jpeg")
ici=codec;
}
EncoderParameters ep=new EncoderParameters();
ep.Param[0]=new EncoderParameter(Encoder.Quality,(long)level);
bm.Save(Server.MapPath("2.jpg"),ici,ep); // ===裁剪图片===
Rectangle cloneRect = new Rectangle(0, 0, CutOut_Width, CutOut_Height);
PixelFormat format = bm.PixelFormat;
Bitmap cloneBitmap = bm.Clone(cloneRect, format); // ===保存图片===
cloneBitmap.Save(Server.MapPath(out_ImgUrl),ici,ep);
} public bool ThumbnailCallback()
{
return false;
}
http://kb.cnblogs.com/page/47074/2/
要结合图片预览怎么做呢
当选择图片时,图片可以显示在那快裁减的框
然后进行裁减!
<div style="background-image:url(1.jpg);width:200px;height:150px; background-position: 50px 50px;"></div>width是pt2.x-pt1.x绝对值
height是pt2.y-pt1.y绝对值
background-position:只用pt1.x和pt1.y就是这样子,大概
<img src="1.jpg" style="width:300px;height:250px; position:relative; left:-50px;top:-50px" />
</div>
这个控件实现与.NET1.1环境中,作为一个ASP.NET控件,它可以允许用户在客户端上传一幅图像到服务器上,并在浏览器中直接对图像进行裁剪、缩放、修改成为一个web可用的图像。