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 90734a3c
authored
Feb 14, 2014
by
Antti Tonkyra
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Image cropping code
1 parent
11c61563
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
0 deletions
code/MoyaBeans/ejbModule/fi/codecrew/moya/beans/UserBean.java
code/MoyaBeans/ejbModule/fi/codecrew/moya/beans/UserBean.java
View file @
90734a3
...
...
@@ -273,6 +273,8 @@ public class UserBean implements UserBeanLocal {
bimage
=
resized
;
}
bimage
=
forceCrop
(
bimage
);
ByteArrayOutputStream
naamaout
=
new
ByteArrayOutputStream
();
try
{
...
...
@@ -296,6 +298,44 @@ public class UserBean implements UserBeanLocal {
return
userimage
;
}
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
));
}
else
{
xl
=
(
int
)(
x
*((
double
)
y
/(
double
)
x
));
yl
=
y
;
}
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
());
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
.
dispose
();
return
cropped
;
}
@Override
public
UserImage
findUserimageFORCE
(
Integer
id
)
...
...
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