我想访问存储在黑莓中的图像,例如位置“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)”访问它吗?

有帮助吗?

解决方案

看一眼 Bitmap.getBitmapResource API参考:

公共静态 Bitmap getBitmapResource(字符串名称)
从提供的名称资源创建位图。
此方法在启动此进程的 cod 文件中查找资源。
参数:
name - 位图资源的名称。
返回:
新的 Bitmap 对象,如果此方法找不到您的命名资源,则返回 null。
投掷:
NullPointerException - 如果 name 参数为 null。
自从:
JDE 3.6

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

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

而且,如果要从文件系统打开一些图像,则必须使用FileConnection,检查文件MIME类型,从流中读取字节并相应地创建编码图。

其他提示

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

位图 JavaDocs

你用什么语言写作?以下是我在 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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top