Results 1 to 10 of 10

Thread: VB - SnipSnap: Copy/Cut & Paste Image Areas

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    VB - SnipSnap: Copy/Cut & Paste Image Areas

    Earlier versions of this were called "MaskoMania" but a lot has been cleaned up and additional functionality added.

    Basically it is a UserControl to be hosted within a container control with a bitmap image. The user can "lasso" a rectangle to be cut or copied, dragged then pasted.

    Code:
    'Mouse Actions:
    '-------------
    '
    'When Enabled = True the mouse performs the following actions.  When Enabled = False
    'the events pass through with no processing.
    '
    'On the container:
    '
    '   Left-click to clear the selection.
    '
    '   Left-drag then release to establish the selection and copy or cut from the
    '   container's bitmap.  See the Cutting property.  A cut operation backfills with
    '   the MaskColor.  A very small drag acts like a click.
    '
    '   Shift-left-click makes Masking = False.
    '
    '   Shift-right-click to choose the color under the mouse as MaskColor and make
    '   Masking = True.
    '
    'On the control:
    '
    '   Left-drag to move the control.
    '
    '   Shift-left-click makes Masking = False.
    '
    '   Right-click pastes the contents of the control into the container bitmap.
    '
    '   Shift-right-click to choose the color under the mouse as MaskColor and make
    '   Masking = True.
    Masking is used to designate a transparent color. Minimalist demo:

    Name:  sshot.png
Views: 1970
Size:  9.3 KB

    There is also another demo in the attachment. It covers a wider set of features available, like passing a snippet from one container to another or loading an external file as a snippet.
    Attached Files Attached Files

  2. #2

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: VB - SnipSnap: Copy/Cut & Paste Image Areas

    I suppose an enhancement might be an optional feature to collapse the selection bounding rectangle to minimum size automatically when there is a mask (transparent) color. I'm not sure whether there might be GDI calls to expedite that.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: VB - SnipSnap: Copy/Cut & Paste Image Areas

    Ok, got bored and implemented this new AutoCrop property. Sort of by brute force, but performance seems adequate.

    Here I set AutoCrop = True at design time:

    Name:  sshot.png
Views: 455
Size:  7.6 KB

    Remember, it crops away the MaskColor (down to a smaller rectangle) so you'll want to set a MaskColor even if you set Masking = False.

    I've included only the UserControl itself here. Just replace it in the demo projects above for a quick test. Be sure to add a button to choose/clear AutoCrop, it defaults to False.


    Oops! Introduced a bug. Now fixed and reposted.

    Updated again with corrections for containers using aberrant ScaleMode settings.
    Attached Files Attached Files
    Last edited by dilettante; Aug 28th, 2020 at 01:49 PM.

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: VB - SnipSnap: Copy/Cut & Paste Image Areas

    Seems to be enough interest, so I'll post another update. Small tweaks and a new Pasted event.

    Name:  sshot3.png
Views: 517
Size:  9.1 KB

    Probably should have yet another property "Pasting" to enable/disable the paste functionality.

    With more use new things suggest themselves.
    Attached Files Attached Files

  5. #5
    Frenzied Member
    Join Date
    May 2014
    Location
    Kallithea Attikis, Greece
    Posts
    1,289

    Re: VB - SnipSnap: Copy/Cut & Paste Image Areas

    When you get something from the left panel, and mouse pointer goes out of that panel then an error occured. Width and Height of the area has to be checked before the copy actual happen.

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: VB - SnipSnap: Copy/Cut & Paste Image Areas

    Not seeing it. What error occurs? What line of code fails?

  7. #7
    Frenzied Member
    Join Date
    May 2014
    Location
    Kallithea Attikis, Greece
    Posts
    1,289

    Re: VB - SnipSnap: Copy/Cut & Paste Image Areas

    Subscript out of range
    ExitLeft:
    If X < .Right Then .Left = X
    For Y = .Top To .Bottom
    For X = .Left To .Right
    If PixelValues(X, Y) <> MaskColorRGB Then GoTo ExitTop
    Next
    Next
    Code:
    X=200
    Y=155
    ? RECT.Left, RECT.Top, RECT.Right, RECT.Bottom 
    113           155           200           200 
    ? BITMAPINFO_32.bmiHeader.biWidth - 1,BITMAPINFO_32.bmiHeader.biHeight - 1
     199          -221
    The BITMAPINFO_32.bmiHeader.biHeight reverse sign two times so I think this is the value -221
    For ReDim PixelValues(.biWidth - 1, .biHeight - 1)


    I use Windows 10 Pro, Version 20H2

    To produce the error:
    Just make a cut from any point to a point out of panel, on the right up or down. If you go to other dierction left no problem..
    Last edited by georgekar; Sep 4th, 2020 at 02:38 PM.

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: VB - SnipSnap: Copy/Cut & Paste Image Areas

    Ok, that helps a lot. I'll look at it when I get a chance tonight.

  9. #9

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: VB - SnipSnap: Copy/Cut & Paste Image Areas

    Found a silly bug. Found another absurd one as well while I was in there. Also added a "Pasting" property.

    I was subtracting 1 but I needed to convert that to ScaleMode units first.

    Seems to be ok now, but I might have broken something else. Be sure to test!
    Attached Files Attached Files

  10. #10
    Frenzied Member
    Join Date
    May 2014
    Location
    Kallithea Attikis, Greece
    Posts
    1,289

    Re: VB - SnipSnap: Copy/Cut & Paste Image Areas

    Tested; OK;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width