-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