#1
Posted
:
Wednesday, November 9, 2016 5:29:11 AM(UTC)
Groups: Registered
Posts: 3
How to select image like MS Paint?
I'm using C# then rasterimageviewer to load an image.
When I click a button, then drag a mouse to the viewer,
like rectangle. After that it will cut the image just like in
paint.
please take a look in paint..
i tried cropcommand but the original image will gone.
i want to crop the image and the original image is still on top.
I dont know if I use the correct class. maybe not cropcommand.
this is my code;
Code:private void viewer_InteractiveUserRectangle(object sender, RasterViewerRectangleEventArgs e)
{
// Check the status of the event
if (e.Status == RasterViewerInteractiveStatus.End && !e.Cancel)
{
// The user has finished drawing a new rectangle (and the operation has not been canceled)
// Get the rectangle and convert it to image coordinates (with view-perspective)
RasterImageViewer viewer = sender as RasterImageViewer;
Rectangle rect = e.Rectangle;
// The user rectangle might have negative width or height (if the user starts the drawing from
// bottom-left corner for example), check for that
if (rect.Left > rect.Right)
rect = Rectangle.FromLTRB(rect.Right, rect.Top, rect.Left, rect.Bottom);
if (rect.Top > rect.Bottom)
rect = Rectangle.FromLTRB(rect.Left, rect.Bottom, rect.Right, rect.Top);
// Account for the view perspective of the image
rect = viewer.ViewerToImageRectangle(rect, true);
try
{
// Set this as the region and invert the colors
RasterImage image = viewer.Image;
CropCommand command = new CropCommand();
command.Rectangle = new LeadRect(rect.Left, rect.Top, rect.Width, rect.Height);
command.Run(image);
}
catch (Exception ex)
{
throw ex;
}
}
}
Edited by moderator Wednesday, November 9, 2016 9:05:11 AM(UTC)
| Reason: syntax highlighting
#2
Posted
:
Thursday, November 10, 2016 3:47:01 PM(UTC)
Groups: Registered, Tech Support, Administrators
Posts: 71
Was thanked: 4 time(s) in 3 post(s)
It looks like the CropCommand is what you are looking for, but you would need to have two images in memory for this to function correctly. One image would be your background image and the other would be the "overlay" image that you would crop then drag around the image:
Code:// Set this as the region and invert the colors
RasterImage croppedImage = viewer.Image.Clone();
CropCommand command = new CropCommand();
command.Rectangle = new LeadRect(rect.Left, rect.Top, rect.Width, rect.Height);
command.Run(croppedImage);
This would give you the actual cropped image as another RasterImage that you can manipulate without making changes to the original image.
If you are trying to make something like in your screen shot of MS Paint, as far as the white square that would be located on the background image where the image was cropped, you should be able to set a region based on the cropped rectangle area on the background image and run the FillCommand with white as the color on just that region alone.
Code:using (RasterRegion region = new RasterRegion(new LeadRect(rect.Left, rect.Top, rect.Width, rect.Height)))
{
// Set it into the image
viewer.Image.SetRegion(null, region, RasterRegionCombineMode.Set);
// Fill the image with a color and save it to disk to show the region
FillCommand cmd = new FillCommand(RasterColor.FromKnownColor(RasterKnownColor.White));
cmd.Run(image);
}
This should give you the cropped image and the background image separate from each other.
Aaron Brasington
Developer Support Engineer
LEAD Technologies, Inc.
#3
Posted
:
Wednesday, December 28, 2016 2:01:30 PM(UTC)
Groups: Registered, Tech Support, Administrators
Posts: 71
Was thanked: 4 time(s) in 3 post(s)
Another option that you may want to consider for implementing the functionality you are looking for would be to leverage the FloaterImage property of the RasterImageViewer.
https://www.leadtools.co...evieweritem-floater.htmlCode:// an interactive mode is done. check if its drawing a region
// if so, convert the region to a floater and set the interactive
// mode so that we can drag the floater
RasterImageViewer viewer = sender as RasterImageViewer;
if (viewer.InteractiveMode == RasterViewerInteractiveMode.Region)
{
viewer.EnableTimer = true;
viewer.RegionToFloater();
viewer.FloaterVisible = true;
viewer.AnimateFloater = true;
viewer.InteractiveMode = RasterViewerInteractiveMode.Floater;
// delete the region since we do not need it anymore
viewer.Image.MakeRegionEmpty();
MessageBox.Show("Move the floater around, double click anywhere on the viewer to combine it with the image");
}
Using the FloaterImage property combined with the RasterImageViewer's interactive modes would allow you to be able to draw a region on the image then pop that region out into a new image which you can then drag around. You would still need to update the original image below the floater image and fill the region on the original image with a color to make it appear the image was "popped out" using the FillCommand, but this would make it easier for you to implement the user interaction on the viewer.
Edited by moderator Monday, February 15, 2021 10:32:27 AM(UTC)
| Reason: Not specified
Aaron Brasington
Developer Support Engineer
LEAD Technologies, Inc.
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.