in

Archived Data Techniques Forums

Save selection (or crop)?

Last post 09-10-2008 4:11 PM by support. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 09-10-2008 9:02 AM

    • MickeF
    • Top 200 Contributor
    • Joined on 09-10-2008
    • Posts 6

    Save selection (or crop)?

    I have figured out how to select a portion of the image, making the selection rectangle persist in the viewer.

    How do I access the selected part of the image, to save it (i.e. to crop the original image)?

    The user needs to be able to scan an image, select part of it and save the selection.

    Mikael

     

    Filed under: , ,
  • 09-10-2008 9:06 AM In reply to

    Re: Save selection (or crop)?

    Hi,

    Once you have the coordinates of the section to save then use the ScaleCommand class to crop the image to  the specified portion and then you can save it using the desired codec. When using the ScaleCommand object you'll need to set the SourceArea to the area of the image to be kept, then set the Width and Height properties to the width and height of that area and then call the Process method to return a new image which is just that portion.

    Sean
    Data Techniques Online Support
  • 09-10-2008 9:11 AM In reply to

    • MickeF
    • Top 200 Contributor
    • Joined on 09-10-2008
    • Posts 6

    Re: Save selection (or crop)?

    Thank you for the quick reply. I figured it out ... Like so: 

    (sender as DTI.ImageMan.Winforms.Viewer).Selection.Persist = true;
    DTI.ImageMan.Commands.
    ScaleCommand sc = new DTI.ImageMan.Commands.ScaleCommand();
    sc.SourceArea = viewer1.Selection.Bounds;
    sc.Width = viewer1.Selection.Bounds.Width;
    sc.Height = viewer1.Selection.Bounds.Height;
    DTI.ImageMan.
    ImImage img = sc.Process(viewer1.Images.CurrentImage);
    pictureBox1.Image = img.GetBitmapImage();

    Mikael

  • 09-10-2008 3:43 PM In reply to

    Re: Save selection (or crop)?

    Hi Mikael,

    That looks good. Remember you can also use the ImageMan viewer control instead of the pictureBox in your last line of code :-)

    Sean
    Data Techniques Online Support
  • 09-10-2008 3:59 PM In reply to

    • MickeF
    • Top 200 Contributor
    • Joined on 09-10-2008
    • Posts 6

    Re: Save selection (or crop)?

    Right ... Just testing. :-)

    I'll also make sure to use the using ( ... ) { ... } statement, to have the objects disposed automatically and immediately.

    Purchased the ImageMan.NET Twain bundle today, thanks to the quick support in this forum.

    Mikael

  • 09-10-2008 4:11 PM In reply to

    Re: Save selection (or crop)?

    Cool, let us know if you have any other questions or suggestions. There will be a CropCommand in a forthcoming release.

    Sean
    Data Techniques Online Support
Page 1 of 1 (6 items)
Copyright 2009 Data Techniques, Inc. All Rights Reserved.