- C# code
public class ImageCropper extends IHttpHandler{ public void ProcessRequest(HttpContext context) { String ImgPath = Convert.ToString(context.Request["p"]); int PointX = Convert.ToInt32(context.Request["x"]); int PointY = Convert.ToInt32(context.Request["y"]); int CutWidth = Convert.ToInt32(context.Request["w"]); int CutHeight = Convert.ToInt32(context.Request["h"]); int PicWidth = Convert.ToInt32(context.Request["pw"]); int PicHeight = Convert.ToInt32(context.Request["ph"]); context.Response.ContentType = "image/jpeg"; ShowImage(HttpContext.Current.Server.MapPath(ImgPath), PointX, PointY, CutWidth, CutHeight, PicWidth, PicHeight).WriteTo(context.Response.OutputStream); } private MemoryStream ShowImage(String path, int PointX, int PointY, int CutWidth, int CutHeight, int PicWidth, int PicHeight) { Image image = Image.FromFile(path); BeanMap bm = new Bitmap(CutWidth, CutHeight, System.Drawing.Imaging.PixelFormat.Format24bppRgb); Graphics graphics = Graphics.FromImage(bm); graphics.DrawImage(image, new Rectangle(0, 0, CutWidth, CutHeight), PointX * image.Width / PicWidth, PointY * image.Height / PicHeight, CutWidth * image.Width / PicWidth, CutHeight * image.Height / PicHeight, GraphicsUnit.Pixel); int a = path.LastIndexOf('.'); int b = path.LastIndexOf('\\'); string _newPic = path.Substring(0, b) + "\\new_" + DateTime.Now.ToFileTimeUtc().ToString("X") + ".jpg"; bm.Save(_newPic, System.Drawing.Imaging.ImageFormat.Jpeg); MemoryStream ms = new MemoryStream(); bm.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); image.Dispose(); graphics.Dispose(); bm.Dispose(); return ms; } public bool IsReusable { get { return false; } }}
------解决方案--------------------
这个要转换成 java 可不太容易吧
你得先把里面要用到的类转换成 java,如IHttpHandler、Image、BeanMap、Graphics、MemoryStream ……
而这些类在实现时又有可能使用到了dot net 类库中的其它类,所以在转换时你又得先把那些类实现一次…… 于是一项浩大的工程就开始了。当年我在公司里做 iNet 干的就是这类活儿。
当然如果你只是想达到上面程序的功能,就另当别论了
------解决方案--------------------
一百分啊 有点心动 有时间再考虑吧
------解决方案--------------------