windows 8 - Crop image with rectangle -
i have image , want crop using rectangle, code below code put image , draw rectangle @ middle of image:
mainpage.xaml:
<canvas x:name="canvas" horizontalalignment="center" verticalalignment="center" width="340" height="480" background="blue"> <image x:name="photo" horizontalalignment="center" verticalalignment="center" manipulationmode="all"> <image.rendertransform> <compositetransform/> </image.rendertransform> </image> <path stroke="black" strokethickness="1"> <path.data> <rectanglegeometry rect="0,0,340,480"/> </path.data> </path> </canvas>
i successful display image , draw rectangle. sample image below:
now want click button crop image within rectangle(not auto clip). rectangle auto added when image loaded. cannot use "point pressed" , "point released". , cannot use "rectangle.clip" because auto clip image. how solve it? thanks
updated: able move image,how bind data , set rectangle coordinate dynamic? code below transform image. thanks.
public sealed partial class mainpage: page { private compositetransform compositetranslation; public mainpage() { this.initializecomponent(); photo.manipulationdelta += composite_manipulationdelta; compositetranslation = new compositetransform(); photo.rendertransform = this.compositetranslation; } void composite_manipulationdelta(object sender, manipulationdeltaroutedeventargs e) { // scale image. compositetranslation.centerx = photo.actualwidth / 2; compositetranslation.centery = photo.actualheight / 2; compositetranslation.scalex *= e.delta.scale; compositetranslation.scaley *= e.delta.scale; compositetranslation.translatex += e.delta.translation.x; compositetranslation.translatey += e.delta.translation.y; } }
i have not used or xaml creates confusion me. created snippet according problem. try , let me know results. have used same image posted
xaml
<page.bottomappbar> <appbar issticky="true" isopen="true"> <button content="crop" click="btncrop_click" /> </appbar> </page.bottomappbar> <grid background="{staticresource applicationpagebackgroundthemebrush}"> <image x:name="photo" horizontalalignment="center" verticalalignment="center" manipulationmode="all" source="http://i.stack.imgur.com/uibsp.png" /> <path x:name="path" stroke="red" strokethickness="3"> <path.data> <rectanglegeometry rect="545,212,440,420"/> </path.data> </path> </grid>
c#
private void btncrop_click(object sender, routedeventargs e) { var _rect = new rectanglegeometry(); _rect.rect = path.data.bounds; photo.clip = _rect; }
Comments
Post a Comment