gpt4 book ai didi

java - 如何加载图像以在 RCP 中查看?

转载 作者:行者123 更新时间:2023-11-30 03:53:52 25 4
gpt4 key购买 nike

我正在开发一个 RCP 插件项目,其中包含某些 View 。首先查看员工详细信息,例如 nameaddress 等。有一个选项可以使用浏览按钮上传员工图像。第二个 View 显示在第一个 View 中输入的详细信息。除照片显示良好。

它在照片标签的位置显示一个红色方 block 。我设置照片的代码如下所示:

 Label photoLabel = new Label(parent, SWT.NONE);
photoLabel.setBounds(420, 233, 100, 106);

photoLabel.setImage(SWTResourceManager.getImage(FormDataViewClass.class,photoUploadPath));

其中 photoUploadPath 是包含上传照片路径的字符串变量。我该如何解决这个问题?

最佳答案

以下代码段帮助我解决了上述问题。

byte[] uploadedImg = null;
try {
File f1 = new File(photoUploadPath);
double fileLen = f1.length();
uploadedImg = new byte[(int) fileLen];
FileInputStream inputStream = new FileInputStream(photoUploadPath);
int nRead = 0;
while ((nRead = inputStream.read(uploadedImg)) != -1) {
System.out.println("!!!!!!!!!!!!!!!!!" + new String(uploadedImg));
}
inputStream.close();

} catch (Exception e2) {
// TODO: handle exception
}

BufferedInputStream inputStreamReader = new BufferedInputStream(new ByteArrayInputStream(uploadedImg));
ImageData imageData = new ImageData(inputStreamReader);
Image image = new Image(Display.getCurrent(), imageData);
photoLabel.setImage(image);

关于java - 如何加载图像以在 RCP 中查看?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23752432/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com