I am trying to get following usecase implemented in Xamarin forms
(Using with SFImageEditor from syncfusion but can try if other options)
Display an image in editor.
Display an initial rectangle.
User resizes the rectangle to best fit and clicks "go".
Need to Capture the coordinates of this rectangle in reference to the image.
Send the image and rectangle coordinates for further processing.
Can someone pls provide guidance on step 4 for identifying the coordinates of the rectangle.
(X Y height width) or (coordinates of 4 corners). Either format is fine.
Appreciate your help.
code to set SFImageEditor in Xamarin.Forms with Syncfusion.
Xaml code
<imageeditor:SfImageEditor x:Name="present_image" >
<imageeditor:SfImageEditor.ToolbarSettings>
<imageeditor:ToolbarSettings IsVisible="True" />
</imageeditor:SfImageEditor.ToolbarSettings>
</imageeditor:SfImageEditor>
code behind
public ImgEditPage( )
{
InitializeComponent();
var origImage = ImageSource.FromUri(
new Uri("https://xxx.xx/xxxxxx.jpg")); ;
present_image.Source = origImage;
}
This will open up the image in an editor window, The editor allows to draw a rectangle object.
User can click the button to draw rectangle I want to get the coordinates of the rectangle drawn by user.
We would like to let you know that the you can get the coordinates of the rectangle added on an image by using the Bounds property. On selecting a shape, ItemSelected event will be triggered. From this, you will get settings of selected shape with Bounds property. The value of the Bounds will be in percentage, the value of the shape frame should fall between 0 and 100. For more information, please refer the below link.
https://www.syncfusion.com/kb/8880/how-to-show-dimension-of-shapes-while-resizing
https://help.syncfusion.com/xamarin/image-editor/shapes#pensettings
You can get the actual bounds of the image rendered in SfImageEditor control using the property ActualImageRenderedBounds.
You can get the original image size by using the property of OriginalImageSize.
Related
I am working with the following code to draw graphics elements on a pictureBox in C#
gGraphics = Graphics.FromImage(bBitMap);
pictureBoxB.Image = bBitMap;
This is working fine. For example:
gGraphics.DrawLine(brownPen, pBegin, pEnd);
I would like to hover over or click with the mouse on say, this line and do something.
Question: Would like to know how with the x,y coordinates of the click I can see that I am near the line so that I can display some information about the line. Is there a list of all graphics objects I drew somewhere or do I build a list of the objects I drew and the locations they cover on the pictureBox? Thanks!
I am working on an assignment right now and was asked to create an app to select an area on image with ability to magnify a part of the image around cursor.
Right now I stuck on the magnifier part. There is a Magnifier control in WPF, but how about UWP? Has anyone had any experience creating magnifier in UWP?
SO far I've found this, but UWP has different API's:
http://csharphelper.com/blog/2015/06/zoom-and-crop-a-picture-in-c/
My logic is:
1. Draw circle around the cursor and re-draw it every time the cursor moves.
2. Take a screenshot (render) specified area around it
3. Magnify the are
4. Fill the circle with the magnified image (Bitmap)
Any tips or suggestions would be much appreciated. Thank you
Draw circle around the cursor and re-draw it every time the cursor moves.
You could register the PointerMoved event for your panel(e.g, Canvas) and get current pointer by using the following method:
private void Canvas_PointerMoved(object sender, PointerRoutedEventArgs e)
{
var pointer = e.GetCurrentPoint(sender as UIElement);
}
And then, you could add a Ellipse on it and set its position by current pointer.
Take a screenshot (render) specified area around it
You could use RenderTargetBitmap class APIs to render specific area.
Magnify the are
You could resize the rendertargetbitmap. Check this thread How to Resize the RenderTargetBitmap.
Fill the circle with the magnified image (Bitmap)
After you get the final rendertargetbitmap, you could use it to make a ImageBrush, then you could specify this ImageBrush to the Ellipse's Fill property like the following:
ellipse.Fill = new ImageBrush() { ImageSource = renderTargetBitmap};
I am just started working in WPF application. Here, I need to get the signature from user. I am using Inkcanvas control to implement this feature.
I am curious on knowing is there a way in Inkcanvas control to crop the stroked region alone with some outer margin. I don't want the empty space of the Inkcanvas container in the output bitmap image. if the signature in too small, I want to crop the region and stretch that into particular size(300x200).
OK, first you need to determine the rectangle to crop (the "stroked region"), then save it to an image.
InkCanvas has a Strokes property that is the collection of ink strokes, you can get the bounds of each Stroke by calling Stroke.GetBound method. Then you can get the Left property of the "stroked region", which is the Left property of the leftmost bounds. And you also get the Right, Top and Bottom in the same way. I hope you can understand my explanation.
Resizing the cropped image to 300x200 should be quite easy, you can find plenty of answers on Stackoverflow.
I think this changed for Windows 10 Universal. In some ways, while different, it may be a bit easier.
With your InkCanvas, you have InkPresenter.StrokeContainer and from there you can get the BoundingRect property, which will give you a ton of details about the bounding rectangle of your strokes (ie x, y, width, height, left, right, etc...)
So, here is what I did:
var bounds = myCanvas.InkPresenter.StrokeContainer.BoundingRect;
var left = bounds.Left;
var right = bounds.Right;
//and so on...
Once you have the bounding rectangle data, it is very easy to crop.
Hope this helps!
I've got a large image in memory which I convert to an System.Windows.Media.ImageBrush and use it as the Fill for a System.Windows.Shapes.Rectangle. You can move this rectangle around with your cursor.
Basically I want to use the rectangle as a "viewport". Thus I need to change which parts of the image get displayed within the rectangle, i.e., define a rectangular subsection of the image.
How can I do that?
I see ImageBrush.Viewport but that doesn't seem to mean the same thing.
I'm open to alternative solutions that don't involve a rectangle, such as drawing directly on a canvas or something, but AFAIK WPF doesn't let you access pixel data directly (at least not easily).
To achieve this your going to have to create your own rectangle user control to allow the user to create/resize a rectangle. Then I would create a CroppedBitmap of the image in the rectangle portion Cropped Bitmap MSDN Stackoverflow example
Edit
No, no, no #Mark, You dont turn the CroppedBitmap into a UserControl. You create a USerControl that exposed the CroppedBitmap. Basically, you create a UserControl with the following DependencyProperties
The Image
The Width of he cropped portion
The Height of the cropped portion
The Left of the cropped portion
Top of the cropped portion
Then as soon as any of these properties your DP callback will do a RenderTargetBitmap Crop of the new region.
I am trying to make a tool in c# which allows the user to put a grid on the screen on a picturebox. At the moment i don't know how to do this, so when a button is clicked, the picturebox comes up with a grid. It needs to be a grid which is spaced out enough that users can find out locations of objects on the picture in the picturebox. Help with what code i can use to do this would be very helpful as i was going to use ControlPaint.DrawGrid but not sure of the values i need to put in it to get my desired effect?
Thanks
Form the Documentation od controlpaint.Drawgrid,
I suppose you need to decide on the cell size in x- amd y-direction and pass this as a size parameter to Drawgrid:
public static void DrawGrid(
Graphics graphics,
Rectangle area,
Size pixelsBetweenDots,
Color backColor
)
for example, a 100*200 pixels square grid would be generated by
setting graphcis to the context you want to draw upon,
Setting area to the top left right and bottom parameters of your image
setting size.x to 100 and size.y to 200
setting color to any color you like.
Update
Something like this should do.
Rectangle myRect = new System.drawings.Rectangle();
myRect.Location := new System.Drawing.Point(0,0);
myRect.Height = 50;
myRect.Width = 50;
Drawgrid(FromImage(yourImage), mygrid , yourImage.Size, System.Drawing.Color.Black);
Disclaimer: i don't develope in c#, so above code is not tested for anything. I just picked stuff from the documentation (msdn).