-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageSize.java
More file actions
64 lines (51 loc) · 1.61 KB
/
ImageSize.java
File metadata and controls
64 lines (51 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package infra.images.util;
import java.awt.image.BufferedImage;
/**
* Wraps image size and density
*
* @author alari
* @since 12/21/12 9:15 PM
*/
public class ImageSize {
final int realWidth;
final int realHeight;
final float density;
final String name;
static public ImageSize extract(BufferedImage image) {
return new ImageSize(image.getWidth(), image.getHeight(), 1f);
}
static public ImageSize buildReal(int realWidth, int realHeight) {
return new ImageSize(realWidth, realHeight, 1f);
}
static public ImageSize buildReal(int realWidth, int realHeight, float density) {
return new ImageSize(realWidth, realHeight, density);
}
static public ImageSize buildFormat(int width, int height, float density) {
return new ImageSize((int) Math.ceil(width * density), (int) Math.ceil(height * density), density);
}
public ImageSize(int realWidth, int realHeight, float density) {
this.realWidth = realWidth;
this.realHeight = realHeight;
this.density = density;
name = Integer.toString(realWidth) + "x" + Integer.toString(realHeight) + "_" + Float.toHexString(density);
}
public int getRealWidth() {
return realWidth;
}
public int getRealHeight() {
return realHeight;
}
public float getDensity() {
return density;
}
public int getWidth() {
return (int) Math.floor(realWidth / density);
}
public int getHeight() {
return (int) Math.floor(realHeight / density);
}
@Override
public String toString() {
return name;
}
}