Establecer ancho y alto en BlackBerry BitmapField
Frecuentes
Visto 1,197 veces
0
¿Cómo configuro el ancho y el alto de un BitmapField en BlackBerry? El siguiente código funciona, pero no puedo mostrar la imagen completa. La pantalla muestra solo una parte de mi imagen.
BitmapField bmp = new BitmapField(connectServerForImage(ImageUrl)) {
protected void layout(int width, int height)
{
setExtent(80, 70);
}
};
2 Respuestas
2
Supongo que estás diciendo que tu BitmapField
está mostrando la imagen que recuperas recortada?
Y le gustaría que esté a escala, tal vez a escala para que se ajuste al tamaño de su BitmapField
? Hay muchas formas de hacerlo, pero una es cambiar el tamaño de la imagen después de descargarla, antes de dársela al BitmapField
:
De esta respuesta sobre el cambio de tamaño de un mapa de bits
public static Bitmap resizeImage(Bitmap originalImage, int newWidth, int newHeight) {
Bitmap newImage = new Bitmap(newWidth, newHeight);
originalImage.scaleInto(newImage, Bitmap.FILTER_BILINEAR, Bitmap.SCALE_TO_FILL);
return newImage;
}
(Tenga en cuenta que el enlace que proporcioné tiene un método alternativo para cambiar el tamaño de las imágenes, si tiene que admitir BlackBerry OS < 5.0).
Luego, use
Bitmap img = resizeImage(connectServerForImage(ImageUrl), 80, 70);
BitmapField bmp = new BitmapField(img) {
protected void layout(int width, int height)
{
setExtent(80, 70);
}
};
Sin embargo, creo que si realmente establece el tamaño de la Bitmap
img
a 80x70, entonces no hay necesidad de además, establecer el alcance de la BitmapField
a 80x70. Debe tener por defecto el tamaño de la imagen que le das. Entonces, podrías simplificar el código a:
BitmapField bmp = new BitmapField(img);
contestado el 23 de mayo de 17 a las 13:05
0
int prefWidth=(30*bitmap.getWidth())/bitmap.getHeight();
Bitmap temp=resizeBitmap(bitmap,prefWidth,30);
sin que importe
private Bitmap resizeBitmap(Bitmap image, int width, int height)
{
int rgb[] = new int[image.getWidth()*image.getHeight()];
image.getARGB(rgb, 0, image.getWidth(), 0, 0, image.getWidth(), image.getHeight());
int rgb2[] = rescaleArray(rgb, image.getWidth(), image.getHeight(), width, height);
Bitmap temp2 = new Bitmap(width, height);
temp2.setARGB(rgb2, 0, width, 0, 0, width, height);
return temp2;
}
Este soporte bb os 4.5
Respondido 15 Oct 12, 08:10
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas blackberry java-me or haz tu propia pregunta.