-1
这是将图像文件转换为字节数组的代码。从Android模拟器中读取图像
public String GetQRCode() throws FileNotFoundException, IOException {
/*
* In this function the first part shows how to convert an image file to
* byte array. The second part of the code shows how to change byte array
* back to a image.
*/
AssetManager mgr = mAppView.getContext().getAssets();
InputStream in = mgr.open("www/Siemens_QR.jpg");
InputStreamReader isr = new InputStreamReader(in);
char[] buf = new char[20];
isr.read(buf, 0, 20);
isr.close();
// byte[] bytes = bos.toByteArray();
String abc = buf.toString();
return abc;
}
这里我将图像文件转换为字节数组。我能够做到这一点。但是,当尝试使用存储在模拟器中的路径(“sdcard/Download/Siemens_QR.jpg”)读取此映像文件时,我正在收到VM中止错误。请建议我读取存储在仿真器中的图像文件的正确路径。
希望的方式,你会做它在模拟器与手机或平板电脑上的操作方式完全相同。如果是这样,问题不是'如何在模拟器中做到这一点?'但'怎么做?'。 – 2012-03-20 08:40:26
你想从IDE模拟器运行这个...? – 2012-03-20 08:40:59