我们可以Bitmap
从 SD 卡图像文件路径创建一个对象吗?
我已经编写了一个示例方法来创建它。这是正确的方法吗?
public Bitmap createBitmap(String filepath){
try {
// filepath e.g. "file:///SDCard/test.jpg"
FileConnection fc = (FileConnection)Connector.open(filepath);
byte[] responseData = new byte[10000];
InputStream inputStream =fc.openDataInputStream();
int length = 0;
StringBuffer rawResponse = new StringBuffer();
while (-1 != (length = inputStream.read(responseData))) {
rawResponse.append(new String(responseData, 0, length));
}
byte[] dataArray = rawResponse.toString().getBytes();
Bitmap bitmap = Bitmap.createBitmapFromBytes(dataArray, 0, dataArray.length, 1);
// EncodedImage.createEncodedImage(dataArray, 0, dataArray.length);
return bitmap;
} catch (IOException e) {
return null;
// TODO Auto-generated catch block
// e.printStackTrace();
}
}