我正在尝试使用html 5图片上传,但我遇到的问题是当我尝试解码64位编码图像时会抛出一些错误,这是我的代码:
public String decodeToImage() throws IOException {
destPath = "/home/user/deskTop";
byte[] imageByte;
String imageData = request.getParameter("img");
String base64Image = imageData.split(",")[1];
BASE64Decoder decoder = new BASE64Decoder();
imageByte = decoder.decodeBuffer(base64Image);
BufferedImage img = ImageIO.read(new ByteArrayInputStream(imageByte));
File outputfile = new File(destPath, "11111.png");
try
{
ImageIO.write(img, "jpg", outputfile);
}
catch(Exception e)
{
e.printStackTrace();
}
return SUCCESS;
}
当我尝试在缓冲区图像的文件中写入图像时,会抛出此错误:
"Invalid argument to native writeImage"
当我在其他地方提出错误时,有人说这可能是因为使用了open-jdk。
这是我的JavaScriot:
crop = function() {
//Find the part of the image that is inside the crop box
var crop_canvas,
left = $('.imgOverlay').offset().left - $container.offset().left,
top = $('.imgOverlay').offset().top - $container.offset().top,
width = $('.imgOverlay').width(),
height = $('.imgOverlay').height();
crop_canvas = document.createElement('canvas');
crop_canvas.width = width;
crop_canvas.height = height;
crop_canvas.getContext('2d').drawImage(image_target, left, top, width, height, 0, 0, width, height);
var onSuccesOfUpload = function(data) {
alert();
};
var onErrorOfUpload = function(data) {
alert();
};
var data = function(data) {
alert();
};
var data = {
'img': crop_canvas.toDataURL("image/png")
};
callToDB('/canvasImageUpload.action', 'POST', data, onSuccesOfUpload, onErrorOfUpload);
}