2017年8月6日 星期日

How to load part of the image base on the height

image = (ImageView)findViewById(R.id.iv);
Bitmap bmp = BitmapFactory.decodeResource(getResources(),R.drawable.ico_star_blue_full);
image.setBackgroundResource(R.drawable.ico_star_blue_empty);
float percent = 0.3f;
int height = (int)(bmp.getHeight() * percent);

Bitmap bmpProgress = bmp.createBitmap(bmp,0,bmp.getHeight()-height,bmp.getWidth(),height);
image.setImageBitmap(bmpProgress);
image.setScaleType(ImageView.ScaleType.FIT_END);





bmp.getHeight()-height is calculate the start point of the pixel,the top of the start point is 0