3

我想访问存储在 Blackberry 中的图像,例如位置 "store/home/user/image.png" 。

现在我可以访问此图像,

String filePath = "file:///store/home/user/image.png;
Bitmap image = Bitmap.getBitmapResource(filePath);
BitmapField bitmapField = new BitmapField(image, BitmapField.FOCUSABLE);

或者

我必须访问它,

  String filePath = "file:///store/home/user/image.png;
  FileConnection fconn = (FileConnection)Connector.open(filePath, Connector.READ); 
  if (fconn.exists()) 
  {
                ........
                ........                           

     input.close();
     fconn.close();                            

  }

我可以使用第二种方式访问​​图像,但我想知道我可以使用 "Bitmap.getBitmapResource(filePath)" 访问它吗?

4

3 回答 3

4

看看Bitmap.getBitmapResource API 参考:

public static Bitmap getBitmapResource(String name)
从提供的名称资源创建位图。
此方法在启动此进程的 cod 文件中查找资源。
参数:
name - 位图资源的名称。
返回:
新的 Bitmap 对象,如果此方法找不到您的命名资源,则返回 null。
抛出:
NullPointerException - 如果 name 参数为 null。
自:
JDE 3.6

public static Bitmap getBitmapResource(String module, String name)
从模块中提供的命名资源创建位图。
参数:
module - 包含位图资源的模块的名称。如果未指定,则使用>调用模块的名称。
name - 位图资源的名称。
返回:
新的 Bitmap 对象,如果此方法找不到您的命名资源,则返回 null。
抛出:
NullPointerException - 如果 name 参数为 null。
自:
JDE 3.6

此方法用于检索资源代码模块。如果您在项目中包含一些图像,您将能够使用此方法检索它。

如果你想从文件系统打开一些图像,你将不得不使用 FileConnection,检查文件 MIME 类型,从流中读取它的字节并相应地创建 EncodedImage。

于 2009-10-27T12:09:07.187 回答
3

Bitmap.getBitmapResource() 用于加载存储在您的 COD 文件或您的应用程序所依赖的任何 COD 文件中的资源。它不适用于加载存储在设备上的文件。

位图 JavaDocs

于 2009-10-27T12:05:51.740 回答
-2

你用什么语言写作?以下是我在 Windows Mobile 上使用 C++ 的方法:

Log::GetSingleton() << "Loading sprite: " << wchar_path << "\n";

// Special magic WM bitmap loading function that isn't in the examples
// because Microsoft wants you to use resource files
HBITMAP bitmap = SHLoadDIBitmap(wchar_path);

if (!bitmap) 
{
    Error::LastError();
    Error::Explain("Failed to load bitmap.");
    return NULL;
}

HDC dc_image = CreateCompatibleDC(NULL);
if (!dc_image) 
{
    Error::LastError();
    Error::Explain("Failed to create memory device context.");
    return NULL;
}
HBITMAP other_bitmap = (HBITMAP)SelectObject(dc_image, bitmap);

wchar_path会是这样的\\Storage Card\\test.bmp

于 2009-10-27T11:39:16.597 回答