Ich habe ein Projekt basierend auf Spring Web Model-View-Controller (MVC) Framework. Die Version des Model-View-Controller-Framework (MVC) von Spring Web ist 3.2.8. Ich lese ein BildJava Lesen/Laden eines Bildes
public static void main(String[] args) {
BufferedImage img = null;
try {
img = ImageIO.read(new File("C:/tmp/device.jpg"));
} catch (IOException e) {
}
System.out.println ("img -> " + img);
}
und es ist die Arbeit mit diesem Ergebnis gut:
img -> [email protected]: type = 5 ColorModel: #pixelBits = 24 numComponents = 3 color space = [email protected] transparency = 1 has alpha = false isAlphaPre = false ByteInterleavedRaster: width = 480 height = 640 #numDataElements 3 dataOff[0] = 2
Aber wenn ich das gleiche Bild in meinem Frühlings-MVC-app laden:
MultipartFile file = productForm.getAttachment();
System.out.println ("productForm.getAttachment() ------------------> " + productForm.getAttachment());
System.out.println ("productForm.getAttachment().getContentType() -> " + productForm.getAttachment().getContentType());
System.out.println ("productForm.getAttachment().getSize() --------> " + productForm.getAttachment().getSize());
byte[] result = new byte[(int) file.getSize()];
Image img = new Image();
img.setContent(result);
ByteArrayInputStream in = new ByteArrayInputStream(img.getContent());
BufferedImage img2 = null;
try {
img2 = ImageIO.read(in);
System.out.println ("IMAGE CONTENT2 ------> " + img2);
} catch (IOException e) {
}
productForm.getAttachment() ------------------> [email protected]f1bc67
productForm.getAttachment().getContentType() -> image/jpeg
productForm.getAttachment().getSize() --------> 28704
, ich habe konfrontiert img2 ist NULL !!!
Hier ist die Klasse Bild
public class Image implements java.io.Serializable {
private Long id;
private byte[] content;
public Image() {
}
public Image(Image image) {
this.id = image.getId();
this.content = image.getContent();
}
public Image(byte[] content) {
this.content = content;
}
@Id
@Column(name = "ID", unique = true, nullable = false, precision = 38, scale = 0)
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
@Column(name = "CONTENT", nullable = false)
@Lob
@Basic(fetch = FetchType.LAZY)
public byte[] getContent() {
return this.content;
}
public void setContent(byte[] content) {
this.content = content;
}
}
Haben Sie diese Datei überprüft, result und img ist nicht null, um sicherzustellen, dass das Problem nicht dort liegt. –
hast du vielleicht eine ... 'IOException'? : D – fantaghirocco
Nein, ich sehe IMAGE CONTENT2 ------> –