如何做RCP里的图片资源管理
2012-04-12 14:21
239 查看
这里我写了一中读取资源图片管理的方法,这个方法的好处就是,加载过的图片把它放在MAP里,下次再用的时候不用重新加载。
1.在这个plugin的最顶层目录下创建 icons文件,然后把图片放在这个文件夹里。
2.在这个plugin 里的Activator(默认是这个类名,一般自己会改成其他和PLUGIN相关的名字)里写static方法,这方法能根据图片所在地路径名字取得图片
注意图片路径可以为/icons/xxx.gif ,也可以为icons/xxx.gif. 因为内部代码会自动转化。如果不用这种办法取得资源路径,那么只能用/icons/xxx.gif绝对路径。O YEA~
3.然后就可以在别的类里根据图片路径读出IMG。
例如。
4.如果想把这个图放在CLabel里。最好这么写。这里我用formLayout.
这样的图大小工整。
1.在这个plugin的最顶层目录下创建 icons文件,然后把图片放在这个文件夹里。
2.在这个plugin 里的Activator(默认是这个类名,一般自己会改成其他和PLUGIN相关的名字)里写static方法,这方法能根据图片所在地路径名字取得图片
public class Activator extends AbstractUIPlugin { ...... public static Image getImage(String path) { return getImage(getDefault().getImageRegistry(), path.toString()); } public static Image getImage(ImageRegistry registry, String path){ try{ Image img= registry.get(path); if(img==null){ ImageDescriptor desc= Activator.imageDescriptorFromPlugin(Activator.class.getPackage().getName(), path); registry.put(path, desc); img= registry.get(path); } return img; }catch(MissingResourceException e){ e.printStackTrace(); } return null; } ...... }
注意图片路径可以为/icons/xxx.gif ,也可以为icons/xxx.gif. 因为内部代码会自动转化。如果不用这种办法取得资源路径,那么只能用/icons/xxx.gif绝对路径。O YEA~
3.然后就可以在别的类里根据图片路径读出IMG。
例如。
class ImgShows{ ...... public Img getImg(String path){ Image img=Activator.getImage(path); } ...... }
4.如果想把这个图放在CLabel里。最好这么写。这里我用formLayout.
Image img=Activator.getImage(imgPath.toString()); CLabel icon = new CLabel(headComposite, SWT.NONE); icon.setBackground(img); final FormData iconFormData = new FormData(); iconFormData.top = new FormAttachment(LAYOUT.ZERO_PERCENT, LAYOUT.MARGIN_TOP_COMPOSITE); iconFormData.left = new FormAttachment(LAYOUT.ZERO_PERCENT, LAYOUT.MARGIN_LEFT_COMPOSITE); iconFormData.width=img.getBounds().width; iconFormData.height=img.getBounds().height; icon.setLayoutData(iconFormData);
这样的图大小工整。
相关文章推荐
- 如何高效管理 React Native 项目中的图片资源
- Android 如何使用网络图片资源
- 如果让你来制作一个访问量很高的大型网站,你会如何来管理所有CSS文件、JS与图片?
- Android ImageView 不显示JPEG图片 及 Android Studio中如何引用图片资源
- [Android]图片资源管理学习
- rcp(插件开发)资源管理二
- rcp(插件开发)eclipse平台图片资源共享的获取方法
- 第四章 Spring.Net 如何管理您的类___统一资源访问接口
- 如何删除xcode项目中不再使用的图片资源
- C#如何使用资源中的图片
- 如何在使用eclipse的情况下,清理android项目中的冗余class文件和资源文件以及冗余图片
- Unity5 如何做资源管理和增量更新
- 如何删除xcode项目中不再使用的图片资源
- Android ImageView 不显示JPEG图片 及 Android Studio中如何引用图片资源
- 在不改变大小的情况下,如何以最省内存的方式读取本地资源的图片
- rcp(插件开发)资源管理三
- 如何编译android源码包res的图片资源
- JAVA:如何将图片等资源打包进jar文件
- 如何删除xcode项目中不再使用的图片资源
- Unity5 如何做资源管理和增量更新