Codenameone 在从openGallery方法上载图像之前,请调整图像大小
我想从图库中调整图像大小,然后将其上载。因为用户可能会选择大尺寸的图像,这可能需要很多时间才能上传。假设我想将图像调整为1024px宽度,并根据宽度重新调整高度比例。我使用openGallery方法,在这里我找不到任何参数来指定要调整img大小的宽度。我想如果我没有弄错的话,(对于相机img)Capture.capturePhoto(Display.getInstance().getDisplayWidth()/2,-1)就可以做到这一点。我如何才能为画廊中的图像实现它?谢谢Codenameone 在从openGallery方法上载图像之前,请调整图像大小,codenameone,Codenameone,我想从图库中调整图像大小,然后将其上载。因为用户可能会选择大尺寸的图像,这可能需要很多时间才能上传。假设我想将图像调整为1024px宽度,并根据宽度重新调整高度比例。我使用openGallery方法,在这里我找不到任何参数来指定要调整img大小的宽度。我想如果我没有弄错的话,(对于相机img)Capture.capturePhoto(Display.getInstance().getDisplayWidth()/2,-1)就可以做到这一点。我如何才能为画廊中的图像实现它?谢谢 Display.g
Display.getInstance().openGallery(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
try {
if (evt == null) {
System.out.println("user cancelled");
return;
}
eventImgpath = (String) evt.getSource();
Image i = Image.createImage(eventImgpath);
eventImage.setIcon(i.scaledWidth(Display.getInstance().getDisplayWidth()));
eventImage.getParent().revalidate();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}, Display.GALLERY_IMAGE);
//sending the img path to connectionRequest
String eventImgPathFinal = eventImgpath;
AddBusinessForumConnection abfc = new AddBusinessForumConnection();
abfc.addBusinessForumConnectionMethod(eventImgPathFinal);
上传img
public void addBusinessForumConnectionMethod(String eventImg) {
ConnectionRequest connectionRequest = new ConnectionRequest() {
@Override
protected void readResponse(InputStream input) throws IOException {
}
@Override
protected void postResponse() {
}
};
AllUrl allUrl = new AllUrl();
connectionRequest.setUrl(allUrl.addBusinessForumUrl);
connectionRequest.setPost(true);
connectionRequest.addArgument("imgUrl", new ImageBase64().getBase64(eventImg));
NetworkManager.getInstance().addToQueueAndWait(connectionRequest);
}
使用ImageIO调整大小:
ByteArrayOutputStream out = = new ByteArrayOutputStream();
ImageIO.getImageIO().save(path, out, ImageIO.FORMAT_JPEG,
maxWidth, -1, 1);
byte [] data = out.toByteArray();