如何加载图像以在RCP中查看? [英] How to load image to view in RCP?

查看:197
本文介绍了如何加载图像以在RCP中查看?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 RCP插件项目,其中包含某些视图。第一个视图需要
员工详细信息,例如 name 地址等。可以使用浏览按钮上传员工图像。第二个视图显示在第一个视图中输入的详细信息。除照片外的所有详细信息均显示精细。

I am developing an RCP plugin project that includes certain views.First view take employee details like name ,address etc.There is an option to upload employee image using browse button.Second view shows the details that have entered in the first view.All details except photo is displaying fine.

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

It shows a red square in the place of photo label. My code for setting photo is shown like this :

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

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

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

where photoUploadPath is string variable that contains the path of uploaded photo. How can I solve this issue?

推荐答案

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

Following code segment helped me to resolve the above problem.

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);

这篇关于如何加载图像以在RCP中查看?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆