Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Antti Väyrynen
/
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 d85cf16b
authored
May 31, 2014
by
Juho Juopperi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix UserBean.forceCrop()
1 parent
e267ae4b
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 @
d85cf16
...
...
@@ -327,38 +327,41 @@ public class UserBean implements UserBeanLocal {
}
private
BufferedImage
forceCrop
(
BufferedImage
source
)
{
int
x
,
y
,
xl
,
yl
,
xh
,
yh
,
xc
,
yc
,
x0
,
y0
,
x1
,
y1
;
double
ar
=
CardPrintBean
.
ASPECT_RATIO
;
// x/y
x
=
source
.
getWidth
();
y
=
source
.
getHeight
();
xc
=
x
/
2
;
yc
=
y
/
2
;
if
(
y
>=
x
)
{
xl
=
x
;
yl
=
(
int
)
(
y
*
((
double
)
x
/
(
double
)
y
));
int
targetWidth
,
targetHeight
;
double
targetRatio
=
CardPrintBean
.
ASPECT_RATIO
;
// x/y
int
sourceWidth
=
source
.
getWidth
();
int
sourceHeight
=
source
.
getHeight
();
int
sourceCenterX
=
sourceWidth
/
2
;
int
sourceCenterY
=
sourceHeight
/
2
;
int
sourceTop
,
sourceLeft
,
sourceRight
,
sourceBottom
;
double
sourceRatio
=
(
double
)
sourceWidth
/
(
double
)
sourceHeight
;
if
(
sourceRatio
>
targetRatio
)
{
// 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
{
xl
=
(
int
)
(
x
*
((
double
)
y
/
(
double
)
x
));
yl
=
y
;
// the pic is too tall - reduce height
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
);
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
());
BufferedImage
cropped
=
new
BufferedImage
(
targetWidth
,
targetHeight
,
source
.
getType
());
Graphics2D
g
=
cropped
.
createGraphics
();
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
();
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