android - How to cut some part of image and show it in imageview

后端 未结 3 1182
花落未央
花落未央 2020-12-11 03:30

I want to show only some part of image in imageview. See following image . \"image

Same example can be f

3条回答
  •  渐次进展
    2020-12-11 04:10

    // Set some constants
    private static final Bitmap SOURCE_BITMAP = BitmapFactory.decodeFile(....); // Get the source Bitmap using your favorite method :-)
    private static final int START_X = 10;
    private static final int START_Y = 15;
    private static final int WIDTH_PX = 100;
    private static final int HEIGHT_PX = 100;
    
    // Crop bitmap
    Bitmap newBitmap = Bitmap.createBitmap(SOURCE_BITMAP, START_X, START_Y, WIDTH_PX, HEIGHT_PX, null, false);
    
    // Assign new bitmap to ImageView
    ImageView image = (ImageView)findViewById(R.id.image_view);
    image.setImageBitmap(newBitmap);
    

提交回复
热议问题