Changeset 120
- Timestamp:
- Sep 9, 2012, 7:49:49 AM (12 years ago)
- Location:
- trunk/Snippets/CropImage
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Snippets/CropImage/ImageCropBox.vb
r119 r120 35 35 36 36 Private Function ApplyMinimalSelection(ByVal SelectionRectangle As Rectangle) As Rectangle 37 Dim MinimalSelectionSize = EffectiveMinimalSelectionSize 37 38 If SelectionRectangle.Width < MinimalSelectionSize.Width Then 38 39 SelectionRectangle.Width = MinimalSelectionSize.Width … … 80 81 _Image = value 81 82 If _Image IsNot Nothing Then 82 SelectionRectangle = New Rectangle(value.Width * 1 / 16, value.Height * 1 / 16, value.Width * 14 / 16, value.Height * 14 / 16 0)83 SelectionRectangle = New Rectangle(value.Width * 1 / 16, value.Height * 1 / 16, value.Width * 14 / 16, value.Height * 14 / 16) 83 84 'SelectionRectangle = New Rectangle(0, 0, value.Width, value.Height) 84 85 _FadeImage = _Image.Clone … … 102 103 ' TODO: Update SelectionRectangle 103 104 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 104 115 End Property 105 116 Public Property SelectionRectangle As Rectangle … … 204 215 Dim Position As Point = e.Location, SourcePosition As Point 205 216 If Capture Then 217 Dim MinimalSelectionSize = EffectiveMinimalSelectionSize 206 218 Dim P1 As Point, P2 As Point 207 Dim NewSelectionRectangle As Rectangle , NewAdjustedSelectionRectangle As Rectangle219 Dim NewSelectionRectangle As Rectangle 208 220 Select Case DragSpotIndex 209 221 Case 0 ' Left Top … … 213 225 SourcePosition = SourcePointFromPoint(Position) 214 226 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 221 230 Case 1 ' Right Top 222 231 P1 = New Point(ClientImageOrigin.X + ClientImageExtent.Width, ClientImageOrigin.Y) … … 225 234 SourcePosition = SourcePointFromPoint(Position) 226 235 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 233 239 Case 2 ' Left Bottom 234 240 P1 = New Point(ClientImageOrigin.X, ClientImageOrigin.Y + ClientImageExtent.Height) … … 237 243 SourcePosition = SourcePointFromPoint(Position) 238 244 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 245 248 Case 3 ' Right Bottom 246 249 P1 = PointFromSourcePoint(New Point(SelectionRectangle.Left + MinimalSelectionSize.Width, SelectionRectangle.Top + MinimalSelectionSize.Height)) … … 249 252 SourcePosition = SourcePointFromPoint(Position) 250 253 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 257 257 Case 4 ' Move 258 258 Dim Move As Size = SourcePointFromPoint(e.Location) - SourcePointFromPoint(MouseDownPosition) -
trunk/Snippets/CropImage/MainForm.vb
r119 r120 10 10 DefaultText = Text 11 11 Box = New ImageCropBox 12 Box.MinimalSelectionSize = New Size( 320, 240)12 Box.MinimalSelectionSize = New Size(80, 60) 13 13 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") 15 15 Controls.Add(Box) 16 16 Box.Dock = DockStyle.Fill
Note: See TracChangeset
for help on using the changeset viewer.