【发布时间】:2016-08-07 00:37:11
【问题描述】:
我想调整图库中的图片大小,然后上传。由于用户可能会选择可能需要很长时间才能上传的大尺寸图像。假设我想将图像的大小调整为 1024px 宽度,并且高度相对于宽度进行重新缩放。我使用了 openGallery 方法,但没有找到任何参数来指定要调整大小的 img 的宽度。我想如果我没记错的话,(对于相机 img) Capture.capturePhoto(Display.getInstance().getDisplayWidth() / 2, -1) 可以解决问题。我如何才能为画廊中的图像实现它?谢谢你
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);
上传图片
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);
}
【问题讨论】:
标签: codenameone