Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Riina Antikainen
/
Moya
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 1c775058
authored
May 31, 2014
by
Antti Tönkyrä
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/forcecrop' into 'master'
forceCrop()
2 parents
adea8c21
d85cf16b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
28 deletions
code/MoyaBeans/ejbModule/fi/codecrew/moya/beans/UserBean.java
code/MoyaBeans/ejbModule/fi/codecrew/moya/beans/UserBean.java
View file @
1c77505
...
@@ -327,38 +327,41 @@ public class UserBean implements UserBeanLocal {
...
@@ -327,38 +327,41 @@ public class UserBean implements UserBeanLocal {
}
}
private
BufferedImage
forceCrop
(
BufferedImage
source
)
{
private
BufferedImage
forceCrop
(
BufferedImage
source
)
{
int
x
,
y
,
xl
,
yl
,
xh
,
yh
,
xc
,
yc
,
x0
,
y0
,
x1
,
y1
;
int
targetWidth
,
targetHeight
;
double
ar
=
CardPrintBean
.
ASPECT_RATIO
;
// x/y
double
targetRatio
=
CardPrintBean
.
ASPECT_RATIO
;
// x/y
x
=
source
.
getWidth
();
int
sourceWidth
=
source
.
getWidth
();
y
=
source
.
getHeight
();
int
sourceHeight
=
source
.
getHeight
();
int
sourceCenterX
=
sourceWidth
/
2
;
xc
=
x
/
2
;
int
sourceCenterY
=
sourceHeight
/
2
;
yc
=
y
/
2
;
int
sourceTop
,
sourceLeft
,
sourceRight
,
sourceBottom
;
if
(
y
>=
x
)
{
double
sourceRatio
=
(
double
)
sourceWidth
/
(
double
)
sourceHeight
;
xl
=
x
;
if
(
sourceRatio
>
targetRatio
)
{
yl
=
(
int
)
(
y
*
((
double
)
x
/
(
double
)
y
));
// the pic is too wide - reduce width
targetWidth
=
(
int
)((
double
)
sourceHeight
*
targetRatio
);
targetHeight
=
sourceHeight
;
// crop box coords - calculate left and right
sourceLeft
=
sourceCenterX
-
(
targetWidth
/
2
);
sourceTop
=
0
;
sourceRight
=
sourceCenterX
+
(
targetWidth
/
2
);
sourceBottom
=
sourceHeight
;
}
else
{
}
else
{
xl
=
(
int
)
(
x
*
((
double
)
y
/
(
double
)
x
));
// the pic is too tall - reduce height
yl
=
y
;
targetWidth
=
sourceWidth
;
targetHeight
=
(
int
)((
double
)
sourceWidth
/
targetRatio
);
// crop box coords - calculate top and bottom
sourceLeft
=
0
;
sourceTop
=
sourceCenterY
-
(
targetHeight
/
2
);
sourceRight
=
sourceWidth
;
sourceBottom
=
sourceCenterY
+
(
targetHeight
/
2
);
}
}
xh
=
(
int
)
((
xl
/
2
)
*
ar
);
BufferedImage
cropped
=
new
BufferedImage
(
targetWidth
,
targetHeight
,
source
.
getType
());
yh
=
yl
/
2
;
x0
=
xc
-
xh
;
x1
=
xc
+
xh
;
y0
=
yc
-
yh
;
y1
=
yc
+
yh
;
int
cix
=
(
int
)
(((
double
)
xl
)
*
ar
);
int
ciy
=
yl
;
BufferedImage
cropped
=
new
BufferedImage
(
cix
,
ciy
,
source
.
getType
());
Graphics2D
g
=
cropped
.
createGraphics
();
Graphics2D
g
=
cropped
.
createGraphics
();
g
.
setRenderingHint
(
RenderingHints
.
KEY_INTERPOLATION
,
RenderingHints
.
VALUE_INTERPOLATION_BILINEAR
);
g
.
setRenderingHint
(
RenderingHints
.
KEY_INTERPOLATION
,
RenderingHints
.
VALUE_INTERPOLATION_BILINEAR
);
g
.
drawImage
(
source
,
0
,
0
,
cix
,
ciy
,
x0
,
y0
,
x1
,
y1
,
null
);
g
.
drawImage
(
source
,
0
,
0
,
targetWidth
,
targetHeight
,
sourceLeft
,
sourceTop
,
sourceRight
,
sourceBottom
,
null
);
g
.
dispose
();
g
.
dispose
();
return
cropped
;
return
cropped
;
...
...
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