There are many overloads in the Canvas class for the drawBitmap () function. One of them allows you to scale / cut Bitmap through a rather convenient interface.
public void drawBitmap (Bitmap bitmap, Rect src, RectF dst, Paint paint)
Where
- A bitmap bitmap is your bitmap that you want to draw
- Rect src - . ,
( src)
- RectF dst - Rect Rectangle,
.
- -
! , 1/2 2 :
float startX = 0;
float startY = 0;
float endX = startX + bitmap.getWidth() * 0.5f;
float endY = startY + bitmap.getHeight() * 2.0f;
canvas.drawBitmap(bitmap, null, new RectF(startX, startY, endX, endY), null);
UPDATE
, , , :
, :
BitmapFactory.Options options = new BitmapFactory.Options();
bitmapOptions.inJustDecodeBounds = true;
BitmapFactory.decodeStream(inputStream, null, options);
BitmapFactory.decodeFile(pathName, options);
int originalWidth = bitmapOptions.outWidth;
int originalHeight = bitmapOptions.outHeight;
, () Bitmap ImageView, , , ( getWidth() getHeight()):
int originalWidth, originalHeight, scaledWidth, scaledHeight;
float scaleWidthRatio = (float)scaledWidth / originalWidth;
float scaleHeightRatio = (float)scaledHeight / originalHeight;