问题描述
div区域内有子div2个,如果根据div显示的内容截图保存,或者后台根据hammer.js得的x,y坐标截图保存图片我可以将当前显示的图片的<inputid="posX"name="posX"value="0"type="hidden"><inputid="posY"name="posY"value="0"type="hidden"><inputid="scale"name="scale"value="1"type="hidden"><inputid="rotation"name="rotation"value="0"type="hidden"><inputid="maskheight"name="maskheight"value=""type="hidden"><inputid="THeight"name="THeight"value=""type="hidden">这些参数传到后台,下面test1就是截图区域<divid="test1"><divid="mask"class="test1_mask"><imgid="maskimg"src="%E5%9B%BE%E7%89%87%E8%A3%81%E5%88%872_files/a1.png"></div><divstyle="position:absolute;top:0px;left:0px;height:100%;"><imgclass="dragImg"id="rect"alt=""src="%E5%9B%BE%E7%89%87%E8%A3%81%E5%88%872_files/39492c48ba7c4252a4e7edc79d4efc84.jpg"ondragstart="returnfalse"></div><divid="tip"style="position:absolute;top:0px;width:100%;height:100%;z-index:999;"align="center"><imgstyle="margin-top:20%"id="Img1"alt=""src="%E5%9B%BE%E7%89%87%E8%A3%81%E5%88%872_files/finger.png"><br><pclass="text">点击图片可进行编辑</p></div><divid="divtxt"style="position:absolute;top:0px;width:100%;height:100%;z-index:999"align="center"><pid="ptxt"style="font-size:2.5em;margin-top:110%;width:80%;height:30%"class="text"></p></div></div>
解决方案
解决方案二:
如何根据这些参数在后台截图*图片切割*@paramimagePath原图地址*@paramx目标切片坐标X轴起点*@paramy目标切片坐标Y轴起点*@paramw目标切片宽度*@paramh目标切片高度
解决方案三:
你这些参数都是按原始图片大小来的还是按你显示的大小来的?下面是获取截图的参考代码///<summary>///获取等比例缩放的图片(高宽不一致时获取最中间部分的图片)///</summary>///<paramname="fromImage"></param>///<paramname="width">要获取的宽度</param>///<paramname="height">要获取的高度</param>///<returns></returns>publicstaticImageAdjImageToFitSize(thisImagefromImage,intwidth,intheight){Bitmapbitmap=newBitmap(width,height);Graphicsgraphics=Graphics.FromImage(bitmap);Pointpoint=newPoint(0,0);Pointpoint2=newPoint(width,0);Pointpoint3=newPoint(0,height);Point[]destPoints=newPoint[]{point,point2,point3};Rectanglerect=GetImageRectangle(fromImage);graphics.DrawImage(fromImage,destPoints,rect,GraphicsUnit.Pixel);Imageimage=Image.FromHbitmap(bitmap.GetHbitmap());bitmap.Dispose();graphics.Dispose();returnimage;}privatestaticRectangleGetImageRectangle(ImagefromImage){//居中位置获取intx=0;inty=0;intheight=fromImage.Height;intwidth=fromImage.Width;if(fromImage.Height>fromImage.Width){height=fromImage.Width;y=(fromImage.Height-fromImage.Width)/2;}else{width=fromImage.Height;x=(fromImage.Width-fromImage.Height)/2;}returnnewRectangle(x,y,width,height);}
解决方案四:
你这应该不能用吧,postx是相对的坐标,posty也是相对坐标,然后根据显示图的大小就是要截取的图大小,实际图的大小来截取的引用2楼starfd的回复:
你这些参数都是按原始图片大小来的还是按你显示的大小来的?下面是获取截图的参考代码///<summary>///获取等比例缩放的图片(高宽不一致时获取最中间部分的图片)///</summary>///<paramname="fromImage"></param>///<paramname="width">要获取的宽度</param>///<paramname="height">要获取的高度</param>///<returns></returns>publicstaticImageAdjImageToFitSize(thisImagefromImage,intwidth,intheight){Bitmapbitmap=newBitmap(width,height);Graphicsgraphics=Graphics.FromImage(bitmap);Pointpoint=newPoint(0,0);Pointpoint2=newPoint(width,0);Pointpoint3=newPoint(0,height);Point[]destPoints=newPoint[]{point,point2,point3};Rectanglerect=GetImageRectangle(fromImage);graphics.DrawImage(fromImage,destPoints,rect,GraphicsUnit.Pixel);Imageimage=Image.FromHbitmap(bitmap.GetHbitmap());bitmap.Dispose();graphics.Dispose();returnimage;}privatestaticRectangleGetImageRectangle(ImagefromImage){//居中位置获取intx=0;inty=0;intheight=fromImage.Height;intwidth=fromImage.Width;if(fromImage.Height>fromImage.Width){height=fromImage.Width;y=(fromImage.Height-fromImage.Width)/2;}else{width=fromImage.Height;x=(fromImage.Width-fromImage.Height)/2;}returnnewRectangle(x,y,width,height);}
解决方案五:
这只是给你举得例子,而且说明都写了这方法是居中截图,你要如果你的x,y,w,h都是页面上等比例过后的,那就要先换算成实际的,然后才能用