Changeset 120


Ignore:
Timestamp:
Sep 9, 2012, 7:49:49 AM (9 years ago)
Author:
roman
Message:
 
Location:
trunk/Snippets/CropImage
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Snippets/CropImage/ImageCropBox.vb

    r119 r120  
    3535
    3636    Private Function ApplyMinimalSelection(ByVal SelectionRectangle As Rectangle) As Rectangle
     37        Dim MinimalSelectionSize = EffectiveMinimalSelectionSize
    3738        If SelectionRectangle.Width < MinimalSelectionSize.Width Then
    3839            SelectionRectangle.Width = MinimalSelectionSize.Width
     
    8081            _Image = value
    8182            If _Image IsNot Nothing Then
    82                 SelectionRectangle = New Rectangle(value.Width * 1 / 16, value.Height * 1 / 16, value.Width * 14 / 16, value.Height * 14 / 160)
     83                SelectionRectangle = New Rectangle(value.Width * 1 / 16, value.Height * 1 / 16, value.Width * 14 / 16, value.Height * 14 / 16)
    8384                'SelectionRectangle = New Rectangle(0, 0, value.Width, value.Height)
    8485                _FadeImage = _Image.Clone
     
    102103            ' TODO: Update SelectionRectangle
    103104        End Set
     105    End Property
     106    Private ReadOnly Property EffectiveMinimalSelectionSize As Size
     107        Get
     108            EffectiveMinimalSelectionSize = MinimalSelectionSize
     109            If MinimalSelectionSize.Width > 0 And MinimalSelectionSize.Height > 0 And PreserveAspectRatio And Image IsNot Nothing Then
     110                Dim Position = New Rectangle(0, 0, MinimalSelectionSize.Width, MinimalSelectionSize.Height)
     111                Dim AdjustedPositon As Rectangle
     112                If ApplyAspectRatio(Position, AdjustedPositon) Then EffectiveMinimalSelectionSize = AdjustedPositon.Size
     113            End If
     114        End Get
    104115    End Property
    105116    Public Property SelectionRectangle As Rectangle
     
    204215        Dim Position As Point = e.Location, SourcePosition As Point
    205216        If Capture Then
     217            Dim MinimalSelectionSize = EffectiveMinimalSelectionSize
    206218            Dim P1 As Point, P2 As Point
    207             Dim NewSelectionRectangle As Rectangle, NewAdjustedSelectionRectangle As Rectangle
     219            Dim NewSelectionRectangle As Rectangle
    208220            Select Case DragSpotIndex
    209221                Case 0 ' Left Top
     
    213225                    SourcePosition = SourcePointFromPoint(Position)
    214226                    NewSelectionRectangle = Rectangle.FromLTRB(SourcePosition.X, SourcePosition.Y, SelectionRectangle.Right, SelectionRectangle.Bottom)
    215                     If ApplyAspectRatio(NewSelectionRectangle, NewAdjustedSelectionRectangle) Then
    216                         NewAdjustedSelectionRectangle.Offset(NewSelectionRectangle.Width - NewAdjustedSelectionRectangle.Width, NewSelectionRectangle.Height - NewAdjustedSelectionRectangle.Height)
    217                         SelectionRectangle = NewAdjustedSelectionRectangle
    218                     Else
    219                         SelectionRectangle = NewSelectionRectangle
    220                     End If
     227                    NewSelectionRectangle = ApplyMinimalSelection(ApplyAspectRatioAndCenterRectangle(NewSelectionRectangle))
     228                    NewSelectionRectangle.Offset(SelectionRectangle.Right - NewSelectionRectangle.Right, SelectionRectangle.Bottom - NewSelectionRectangle.Bottom)
     229                    SelectionRectangle = NewSelectionRectangle
    221230                Case 1 ' Right Top
    222231                    P1 = New Point(ClientImageOrigin.X + ClientImageExtent.Width, ClientImageOrigin.Y)
     
    225234                    SourcePosition = SourcePointFromPoint(Position)
    226235                    NewSelectionRectangle = Rectangle.FromLTRB(SelectionRectangle.Left, SourcePosition.Y, SourcePosition.X, SelectionRectangle.Bottom)
    227                     If ApplyAspectRatio(NewSelectionRectangle, NewAdjustedSelectionRectangle) Then
    228                         NewAdjustedSelectionRectangle.Offset(0, NewSelectionRectangle.Height - NewAdjustedSelectionRectangle.Height)
    229                         SelectionRectangle = NewAdjustedSelectionRectangle
    230                     Else
    231                         SelectionRectangle = NewSelectionRectangle
    232                     End If
     236                    NewSelectionRectangle = ApplyMinimalSelection(ApplyAspectRatioAndCenterRectangle(NewSelectionRectangle))
     237                    NewSelectionRectangle.Offset(SelectionRectangle.Left - NewSelectionRectangle.Left, SelectionRectangle.Bottom - NewSelectionRectangle.Bottom)
     238                    SelectionRectangle = NewSelectionRectangle
    233239                Case 2 ' Left Bottom
    234240                    P1 = New Point(ClientImageOrigin.X, ClientImageOrigin.Y + ClientImageExtent.Height)
     
    237243                    SourcePosition = SourcePointFromPoint(Position)
    238244                    NewSelectionRectangle = Rectangle.FromLTRB(SourcePosition.X, SelectionRectangle.Top, SelectionRectangle.Right, SourcePosition.Y)
    239                     If ApplyAspectRatio(NewSelectionRectangle, NewAdjustedSelectionRectangle) Then
    240                         NewAdjustedSelectionRectangle.Offset(NewSelectionRectangle.Width - NewAdjustedSelectionRectangle.Width, 0)
    241                         SelectionRectangle = NewAdjustedSelectionRectangle
    242                     Else
    243                         SelectionRectangle = NewSelectionRectangle
    244                     End If
     245                    NewSelectionRectangle = ApplyMinimalSelection(ApplyAspectRatioAndCenterRectangle(NewSelectionRectangle))
     246                    NewSelectionRectangle.Offset(SelectionRectangle.Right - NewSelectionRectangle.Right, SelectionRectangle.Top - NewSelectionRectangle.Top)
     247                    SelectionRectangle = NewSelectionRectangle
    245248                Case 3 ' Right Bottom
    246249                    P1 = PointFromSourcePoint(New Point(SelectionRectangle.Left + MinimalSelectionSize.Width, SelectionRectangle.Top + MinimalSelectionSize.Height))
     
    249252                    SourcePosition = SourcePointFromPoint(Position)
    250253                    NewSelectionRectangle = Rectangle.FromLTRB(SelectionRectangle.Left, SelectionRectangle.Top, SourcePosition.X, SourcePosition.Y)
    251                     If ApplyAspectRatio(NewSelectionRectangle, NewAdjustedSelectionRectangle) Then
    252                         'NewAdjustedSelectionRectangle.Offset(0, 0)
    253                         SelectionRectangle = NewAdjustedSelectionRectangle
    254                     Else
    255                         SelectionRectangle = NewSelectionRectangle
    256                     End If
     254                    NewSelectionRectangle = ApplyMinimalSelection(ApplyAspectRatioAndCenterRectangle(NewSelectionRectangle))
     255                    NewSelectionRectangle.Offset(SelectionRectangle.Left - NewSelectionRectangle.Left, SelectionRectangle.Top - NewSelectionRectangle.Top)
     256                    SelectionRectangle = NewSelectionRectangle
    257257                Case 4 ' Move
    258258                    Dim Move As Size = SourcePointFromPoint(e.Location) - SourcePointFromPoint(MouseDownPosition)
  • trunk/Snippets/CropImage/MainForm.vb

    r119 r120  
    1010        DefaultText = Text
    1111        Box = New ImageCropBox
    12         Box.MinimalSelectionSize = New Size(320, 240)
     12        Box.MinimalSelectionSize = New Size(80, 60)
    1313        Box.PreserveAspectRatio = True
    14         Box.Image = Bitmap.FromFile("D:\Projects\Alax.Info\Repository-Public\Snippets\CropImage\20120821_185619.jpg")
     14        Box.Image = Bitmap.FromFile("D:\Projects\Alax.Info\Repository-Public\Snippets\CropImage\20120821_185619 (720x480).jpg")
    1515        Controls.Add(Box)
    1616        Box.Dock = DockStyle.Fill
Note: See TracChangeset for help on using the changeset viewer.