Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Joona Romppanen
/
Moya Info Tools
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 2947ab57
authored
Jun 04, 2017
by
Tapio Haapala
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Image crop fix
1 parent
aa3c033b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
83 additions
and
7 deletions
MoyaSignup/Filters.cs
MoyaSignup/TakePictureControl.cs
MoyaSignup/Filters.cs
View file @
2947ab5
...
...
@@ -1042,7 +1042,83 @@ namespace ImageFilters
grPhoto
.
Dispose
();
return
bmPhoto
;
}
public
static
Image
Crop
(
Image
imgPhoto
,
int
Width
,
int
Height
,
AnchorPosition
Anchor
,
int
x
,
int
y
)
public
static
Bitmap
Crop
(
Bitmap
bmpPhoto
,
int
Width
,
int
Height
,
AnchorPosition
Anchor
)
{
//Scale crop
int
sourceWidth
=
bmpPhoto
.
Width
;
int
sourceHeight
=
bmpPhoto
.
Height
;
int
sourceX
=
0
;
int
sourceY
=
0
;
int
destX
=
0
;
int
destY
=
0
;
float
nPercent
=
0
;
float
nPercentW
=
0
;
float
nPercentH
=
0
;
nPercentW
=
((
float
)
Width
/
(
float
)
sourceWidth
);
nPercentH
=
((
float
)
Height
/
(
float
)
sourceHeight
);
if
(
nPercentH
<
nPercentW
)
{
nPercent
=
nPercentW
;
switch
(
Anchor
)
{
case
AnchorPosition
.
Top
:
destY
=
0
;
break
;
case
AnchorPosition
.
Bottom
:
destY
=
(
int
)
(
Height
-
(
sourceHeight
*
nPercent
));
break
;
default
:
destY
=
(
int
)
((
Height
-
(
sourceHeight
*
nPercent
))
/
2
);
break
;
}
}
else
{
nPercent
=
nPercentH
;
switch
(
Anchor
)
{
case
AnchorPosition
.
Left
:
destX
=
0
;
break
;
case
AnchorPosition
.
Right
:
destX
=
(
int
)
(
Width
-
(
sourceWidth
*
nPercent
));
break
;
default
:
destX
=
(
int
)
((
Width
-
(
sourceWidth
*
nPercent
))
/
2
);
break
;
}
}
int
destWidth
=
(
int
)(
sourceWidth
*
nPercent
);
int
destHeight
=
(
int
)(
sourceHeight
*
nPercent
);
Bitmap
bmPhoto
=
new
Bitmap
(
Width
,
Height
,
PixelFormat
.
Format24bppRgb
);
bmPhoto
.
SetResolution
(
bmpPhoto
.
HorizontalResolution
,
bmpPhoto
.
VerticalResolution
);
Graphics
grPhoto
=
Graphics
.
FromImage
(
bmPhoto
);
grPhoto
.
InterpolationMode
=
InterpolationMode
.
HighQualityBicubic
;
grPhoto
.
DrawImage
(
bmpPhoto
,
new
Rectangle
(
destX
,
destY
,
destWidth
,
destHeight
),
new
Rectangle
(
sourceX
,
sourceY
,
sourceWidth
,
sourceHeight
),
GraphicsUnit
.
Pixel
);
grPhoto
.
Dispose
();
return
bmPhoto
;
}
public
static
Image
Crop
(
Image
imgPhoto
,
int
Width
,
int
Height
,
AnchorPosition
Anchor
,
int
x
,
int
y
)
{
// Size crop
int
sourceWidth
=
imgPhoto
.
Width
;
...
...
MoyaSignup/TakePictureControl.cs
View file @
2947ab5
...
...
@@ -223,13 +223,13 @@ namespace MoyaSignup
if
(
c
==
null
)
c
=
CameraService
.
AvailableCameras
.
First
();
setFrameSource
(
new
CameraFrameSource
(
c
));
_frameSource
.
Camera
.
CaptureWidth
=
1280
;
_frameSource
.
Camera
.
CaptureHeight
=
720
;
//
_frameSource.Camera.CaptureWidth = 1280;
//
_frameSource.Camera.CaptureHeight = 720;
//
_frameSource.Camera.CaptureWidth = 640;
//
_frameSource.Camera.CaptureHeight = 480;
_frameSource
.
Camera
.
CaptureWidth
=
640
;
_frameSource
.
Camera
.
CaptureHeight
=
480
;
_frameSource
.
Camera
.
Fps
=
50
;
_frameSource
.
Camera
.
Fps
=
15
;
_frameSource
.
NewFrame
+=
OnImageCaptured
;
pbIncoming
.
Paint
+=
new
PaintEventHandler
(
drawLatestImage
);
...
...
@@ -271,7 +271,7 @@ namespace MoyaSignup
int
y
=
(
frame
.
Image
.
Height
-
RetangleHeight
)/
2
;
y
=
frame
.
Image
.
Height
-
y
;
latestFrame
=
BitmapFilter
.
Crop
(
frame
.
Image
,
RetangleWidth
,
RetangleHeight
,
ImageFilters
.
BitmapFilter
.
AnchorPosition
.
Free
,
0
,
0
);
latestFrame
=
BitmapFilter
.
Crop
(
frame
.
Image
,
RetangleWidth
,
RetangleHeight
,
ImageFilters
.
BitmapFilter
.
AnchorPosition
.
Free
);
//_latestFrame.RotateFlip(RotateFlipType.RotateNoneFlipY);
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment