Por ejemplo, quiero un borde blanco de 10 píxeles alrededor de los 4 lados del mapa de bits. No lo estoy usando para la vista de imagen Actualmente estoy usando este código para recortar la imagen. ¿Puedo saber cómo podría agregar un borde blanco en él?¿Cómo crear un borde blanco alrededor de mapa de bits?
public Bitmap scaleCenterCrop(Bitmap source, int newHeight, int newWidth) {
int sourceWidth = source.getWidth();
int sourceHeight = source.getHeight();
// Compute the scaling factors to fit the new height and width, respectively.
// To cover the final image, the final scaling will be the bigger
// of these two.
float xScale = (float) newWidth/sourceWidth;
float yScale = (float) newHeight/sourceHeight;
float scale = Math.max(xScale, yScale);
// Now get the size of the source bitmap when scaled
float scaledWidth = scale * sourceWidth;
float scaledHeight = scale * sourceHeight;
// Let's find out the upper left coordinates if the scaled bitmap
// should be centered in the new size give by the parameters
float left = (newWidth - scaledWidth)/2;
float top = (newHeight - scaledHeight)/2;
// The target rectangle for the new, scaled version of the source bitmap will now
// be
RectF targetRect = new RectF(left, top, left + scaledWidth, top + scaledHeight);
// Finally, we create a new bitmap of the specified size and draw our new,
// scaled bitmap onto it.
Bitmap dest = Bitmap.createBitmap(newWidth, newHeight, source.getConfig());
Canvas canvas = new Canvas(dest);
canvas.drawBitmap(source, null, targetRect, null);
return dest;
}
no funcione. el borde blanco de la imagen no aparece en 4 lados. solo un borde para la parte superior e inferior – ericlee
, así tiene la idea básica de jugar con el objetivo y el tamaño del mapa de bits para obtener el efecto que desea. – caguilar187