BlackBerry: crea un objeto de mapa de bits a partir de una imagen de tarjeta SD
Frecuentes
Visto 284 veces
0
¿Podemos crear un Bitmap
objeto de la ruta del archivo de imagen de la tarjeta SD?
He escrito un método de muestra para crearlo. ¿Es el enfoque correcto?
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();
}
}
1 Respuestas
0
public final class MyScreen extiende MainScreen {
Bitmap bit, bit1;
BitmapField bitf[] = new BitmapField[12];
FileConnection fc;
FlowFieldManager grid;
String[] imgpath = { "bharat.png", "fighter1.jpg", "fighter2.jpg",
"fighter3.jpg", "fighter4.jpg", "fighter5.jpg", "fighter7.jpg",
"fighter8.jpg", "fighter9.jpg", "fighter10.jpg", "fighter11.jpg",
"fighter6.jpg" };
String compath = "file:///SDCard/";`enter code here`
public MyScreen() {
grid = new FlowFieldManager();
try {
setTitle("Bharat Title");
for (int i = 0; i < imgpath.length; i++) {
fc = (FileConnection) Connector.open(compath + imgpath[i]);
DataInputStream in = fc.openDataInputStream();
int size = (int) fc.fileSize();
byte[] bb = new byte[size];
bb = IOUtilities.streamToBytes(in);
bit = bit.createBitmapFromBytes(bb, 0, bb.length, 1);
bit1 = new Bitmap(120, 120);
bit.scaleInto(bit1, Bitmap.FILTER_BOX);
bitf[i] = new BitmapField(bit1, FOCUSABLE);
grid.add(bitf[i]);
fc.close();
}
}
catch (Exception ex)
{
ex.getMessage();
}
finally {
try {
fc.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
add(grid);
}
}
contestado el 22 de mayo de 12 a las 12:05
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas blackberry or haz tu propia pregunta.
¿Podemos crear un mapa de bits con la altura y el ancho de la imagen de origen? - user1407894