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};
Related
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.
I was wondering if there is any possible way to position a background image on a button in C# windows forms? I am using Visual Studio 2013, and I noticed that you can use the BackgroundImageLayout but that is very limited. I would like to move the background image around by pixel position, or relative to the button. Kind of like this:
I have been on google for a while now with no luck. If anyone could point me in the right direction, or show my an article to read it would be greatly appreciated. Thank you.
You could use the Paint event (or subclass Button to override OnPaint) to draw the image yourself:
private void myButton_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawImage(myImage, myButton.ClientRectangle);
}
You could then use the TextAlign and Padding properties to control the location of the text.
Note that you should not assign the image to the Button's Image or BackgroundImage properties, otherwise .NET will also render the image.
I am creating a screen capture & crop utility using answer posted here
The code draws a rectangle (System.Drawing.Rectangle) on the screen and saves a cropped image.
I need to make this rectangle movable to a different area on the screen without changing the size.
How can I achieve this?
What did not work for me?
I tried this codeproject article, works very good to move controls on the screen.
For this code to work correctly I would need to draw rectangle on a container control.
Which container can be used to wrapping?
Being a succesful web developer I used to think that I can write for WinForms also... I was wrong :-( Some help would be much appreciated!
In C# Windows Forms to change the location of a rectangle you do the following
rect.Location = new Location(x,y);
Where x and y are the coordinates (relative to the window's origin) that you want to move it to.
Here's a link to The MSDN Page on System.Drawing.Rectangle
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).