eclipse - EncodedImage.getEncodedImageResource 无法在 Eclipse 中加载具有相同名称不同子文件夹的图像(黑莓插件)

标签 eclipse image plugins blackberry

我正在为 Eclipse 使用 Blackberry JDE Plugin v1.3,我正在尝试使用这段代码来创建一个 BitmapField,我一直都是这样做的:

this.bitmap = EncodedImage.getEncodedImageResource("ico_01.png");
this.bitmap = this.bitmap.scaleImage32(
                  this.conf.getWidthScale(), this.conf.getHeightScale());
this.imagenLoad = new BitmapField(this.bitmap.getBitmap(), this.style);

它工作正常,没有错误,但现在我有这组具有相同名称但在不同子文件夹中的图像,如下所示:

enter image description here

出于解释原因,我把它做得比实际小。我不想重命名这些文件,所以它们都不同。我想知道如何访问不同的子文件夹。 “res/img/on/ico_01.jpg”、“img/on/ico_01.jpg”、“on/ico_01.jpg”是我尝试过但失败的一些例子。

最佳答案

看来EncodedImage.getEncodedImageResource(filename)将检索 filename 的第一个实例无论它在您的资源目录树中的哪个位置。

如果您在不同目录中拥有相同文件名的图像(如您所见),这不是很有帮助。

我使用的解决方案是创建我自己的方法,该方法可以根据路径和文件名返回图像。

public static Bitmap getBitmapFromResource(String resourceFilename){

    Bitmap imageBitmap = null;

    //get the image as a byte stream
    InputStream imageStream = getInstance().getClass().getResourceAsStream(resourceFilename);
    //load it into memory
    byte imageBytes[];
    try {

        imageBytes = IOUtilities.streamToBytes(imageStream);
        //create the bitmap
        imageBitmap = Bitmap.createBitmapFromBytes(imageBytes, 0, imageBytes.length, 1);

    } catch (IOException e) {
        Logger.log("Error loading: "+resourceFilename+". "+e.getMessage());
    }

    return imageBitmap;
}

关于eclipse - EncodedImage.getEncodedImageResource 无法在 Eclipse 中加载具有相同名称不同子文件夹的图像(黑莓插件),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7408273/

相关文章:

eclipse - 在 Eclipse 中将换行符从 CRLF 更改为 LF

java - 在 Eclipse 中重命名包

eclipse e4(朱诺): Not able to hide view Part minimize/maximize buttons

javascript - 使用 jQuery/JavaScript 进行组合键

eclipse - 如何使用 Maven 和 Tomcat 在 Eclipse 中启动、调试和构建 Java Web 项目

javascript - 使用 Javascript 删除除文本之外的所有内部 HTML

html - 取消设置最大宽度 :100% and height:auto;

c++ - 如何在Qt中抓取视频帧?

eclipse - Eclipse 中有没有办法确定什么在消耗 CPU 时间?

grails - 'groovy' 和 'grails-web' 插件 gradle 之间的冲突