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)
{
if (e.Status == RasterViewerInteractiveStatus.End && !e.Cancel)
{
RasterImageViewer viewer = sender as RasterImageViewer;
Rectangle rect = e.Rectangle;
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);
rect = viewer.ViewerToImageRectangle(rect, true);
try
{
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 8 years ago
| Reason: syntax highlighting
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:
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)))
{
viewer.Image.SetRegion(null, region, RasterRegionCombineMode.Set);
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.

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:
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;
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 4 years ago
| 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.