GWT Java图像处理使用IUploader显示新图像以替换现有图像
我正在从数据库中获取徽章列表,显示带有说明的徽章图片,并允许用户更改图片。当用户选择新图片时,它不会显示,我无法找出原因(日志中没有错误消息)。正在触发IUploader,后面跟着OnLoadPreloadedImageHandler
任何帮助都将不胜感激
有关守则如下:
for (final Six sixDescription : sixList) {
//Determine whether or not to display archived Six
if ((showArchived.equals("Yes")) ||
((showArchived.equals("No")) && (sixDescription.getSixArchived() == null))) {
//Store the Six Primary Key.
final String storeSixID = sixDescription.getSixId();
// A panel where the thumbnails of upload images will be shown
final HorizontalPanel existingPanelImages = new HorizontalPanel();
//Increment the row index.
row++;row++;
//Allow update of a Six badge
//Six replacement Picture Handler
// Load the image in the document and in the case of success attach it to the viewer
// Attach a replacement image to the pictures viewer
final OnLoadPreloadedImageHandler showNewImage = new OnLoadPreloadedImageHandler() {
public void onLoad(PreloadedImage image) {
image.setWidth("75px");
existingPanelImages.clear();
existingPanelImages.add(image);
Window.alert("OnLoadPreloadedImageHandler");
}
};
final IUploader.OnFinishUploaderHandler onReplaceFinishUploaderHandler = new IUploader.OnFinishUploaderHandler() {
@SuppressWarnings("deprecation")
public void onFinish(IUploader uploader) {
if (uploader.getStatus() == Status.SUCCESS) {
new PreloadedImage(uploader.fileUrl(), showNewImage);
//The server sends useful information to the client by default
UploadedInfo info = uploader.getServerInfo();
System.out.println("File name " + info.name);
System.out.println("File content-type " + info.ctype);
System.out.println("File size " + info.size);
// You can send any customised message and parse it
System.out.println("Server message " + info.message);
//Store path to image;
imagePath = info.message;
if (info.name != null) {
fileName.setText(info.name);
}
Window.alert("IUploader");
}
}
};
// Attach the image viewer to the document so we can get the Award image.
//TODO Delete temporary image when finished.
Window.alert("Existing");
flexTable_Existing.setWidget(row, 0, existingPanelImages);
existingPanelImages.setSize("75", "75");
existingPanelImages.setBorderWidth(1);
existingPanelImages.clear();
existingPanelImages.setStyleName("gwt-TextBox");
flexTable_Existing.getCellFormatter().setVerticalAlignment(row, 0, HasVerticalAlignment.ALIGN_TOP);
flexTable_Existing.getCellFormatter().setHorizontalAlignment(row, 0, HasHorizontalAlignment.ALIGN_CENTER);
//Display the current image.
String imageDataString = sixDescription.getSixPicture();
Image existingImage = new Image(imageDataString);
existingImage.setWidth("75px");
existingImage.setHeight("75px");
existingImage.setStyleName("gwt-TextBox");
flexTable_Existing.setWidget(row, 0, existingImage);
// Create a new uploader panel and attach it to a document
SingleUploader defaultUploader = new SingleUploader();
defaultUploader.setAutoSubmit(true);
defaultUploader.setValidExtensions("gif");
defaultUploader.setEnabled(true);
defaultUploader.avoidRepeatFiles(false);
defaultUploader.setStyleName("gwt-TextBox");
// Add a finish handler which will load the image once the upload finishes
defaultUploader.addOnFinishUploadHandler(onReplaceFinishUploaderHandler);
defaultUploader.getFileInput().getWidget().setStyleName("customButton");
defaultUploader.getFileInput().getWidget().setSize("180px", "20px");
row++;
flexTable_Existing.setWidget(row, 0, defaultUploader);
flexTable_Existing.getCellFormatter().setVerticalAlignment(row, 0, HasVerticalAlignment.ALIGN_MIDDLE);
flexTable_Existing.getCellFormatter().setHorizontalAlignment(row, 0, HasHorizontalAlignment.ALIGN_LEFT);
////////////////////////////////////////////////////////////////////////////////
row--;
//Allow update of a Six Name
final TextBox textBoxExistingSixName = new TextBox();
textBoxExistingSixName.setStyleName("gwt-TextBox");
textBoxExistingSixName.setText(sixDescription.getSixName());
textBoxExistingSixName.setWidth("100px");
flexTable_Existing.setWidget(row, 1, textBoxExistingSixName);
flexTable_Existing.getCellFormatter().setVerticalAlignment(row, 1, HasVerticalAlignment.ALIGN_MIDDLE);
flexTable_Existing.getCellFormatter().setHorizontalAlignment(row, 1, HasHorizontalAlignment.ALIGN_LEFT);
//Allow update of an archive date for the Six
final DateBox dateBoxExistingArchived = new DateBox();
dateBoxExistingArchived.setFormat(new DefaultFormat(DateTimeFormat.getFormat("dd/MM/yyyy")));
dateBoxExistingArchived.setStyleName("gwt-TextBox");
dateBoxExistingArchived.setValue(sixDescription.getSixArchived());
dateBoxExistingArchived.setWidth("100px");
flexTable_Existing.setWidget(row, 2, dateBoxExistingArchived);
flexTable_Existing.getCellFormatter().setVerticalAlignment(row, 2, HasVerticalAlignment.ALIGN_MIDDLE);
flexTable_Existing.getCellFormatter().setHorizontalAlignment(row, 2, HasHorizontalAlignment.ALIGN_LEFT);
}
}
}
# 1 楼答案
我已通过更改以下代码解决了问题:
我现在遇到的问题是,图像显示的是全尺寸,而不是75px乘以75px
我希望这对其他人有所帮助
问候,
格林