add mediaType, width, height, and nbcolors to Image object
This commit is contained in:
1 parent
8dfcf764df
commit
829a7871b0
1 file changed
+47
-3
@@ -1,15 +1,39 @@
|
|||||||
package pdl.backend;
|
package pdl.backend;
|
||||||
|
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URLConnection;
|
||||||
|
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.util.MimeType;
|
||||||
|
|
||||||
public class Image {
|
public class Image {
|
||||||
private static Long count = Long.valueOf(0);
|
private static Long count = Long.valueOf(0);
|
||||||
private Long id;
|
private final Long id;
|
||||||
private String name;
|
private String name;
|
||||||
private byte[] data;
|
private final byte[] data;
|
||||||
|
private final MediaType mediaType;
|
||||||
|
private final int width;
|
||||||
|
private final int height;
|
||||||
|
private final int nbColors;
|
||||||
|
|
||||||
public Image(final String name, final byte[] data) {
|
public Image(final String name, final byte[] data) throws IOException {
|
||||||
id = count++;
|
id = count++;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.data = data;
|
this.data = data;
|
||||||
|
this.mediaType = MediaType.valueOf(URLConnection.guessContentTypeFromName(name));
|
||||||
|
BufferedImage bufImg = ImageIO.read(new ByteArrayInputStream(data));
|
||||||
|
this.width = bufImg.getWidth();
|
||||||
|
this.height = bufImg.getHeight();
|
||||||
|
this.nbColors = bufImg.getColorModel().getNumComponents();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public MediaType getMediaType() {
|
||||||
|
return mediaType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getId() {
|
public long getId() {
|
||||||
@@ -27,4 +51,24 @@ public class Image {
|
|||||||
public byte[] getData() {
|
public byte[] getData() {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Long getCount() {
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getWidth() {
|
||||||
|
return width;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getHeight() {
|
||||||
|
return height;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getNbColors() {
|
||||||
|
return nbColors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSize() {
|
||||||
|
return this.getWidth() + "*" + this.getHeight() + "*" + this.getNbColors();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user