答案 0 :(得分:0)
您可以使用this library解决问题:
代码示例可能如下所示:
mageView mImageView;
PhotoViewAttacher mAttacher;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Any implementation of ImageView can be used!
mImageView = (ImageView) findViewById(R.id.iv_photo);
// Set the Drawable displayed
Drawable bitmap = getResources().getDrawable(R.drawable.wallpaper);
mImageView.setImageDrawable(bitmap);
// Attach a PhotoViewAttacher, which takes care of all of the zooming functionality.
mAttacher = new PhotoViewAttacher(mImageView);
}
// If you later call mImageView.setImageDrawable/setImageBitmap/setImageResource/etc then you just need to call
attacher.update();
否则,您只需阅读有关Android文档转换和动画的the documentation即可。甚至有很多例子。
答案 1 :(得分:0)
我使用以下方法做到了:)
public Bitmap getImageAlbumCover (Bitmap sourceBitmap) {
Bitmap resultBitmap = Bitmap.createBitmap(sourceBitmap, 0, 0,
sourceBitmap.getWidth()-1, sourceBitmap.getHeight()-1);
int padding = 15;
int width = resultBitmap.getWidth();
int height = resultBitmap.getHeight();
Canvas canvas = new Canvas(resultBitmap);
Rect srcRect = new Rect(0, 0, width, height);
Rect desrect1 = new Rect((-1 * 1 * padding), (3 * padding) , width + (-1 * 1 * padding), height + (-1 * 3 * padding));
Rect desrect2 = new Rect((-1 * 2 * padding), (2 * padding) , width + (-1 * 2 * padding), height + (-1 * 2 * padding));
Rect desrect3 = new Rect((-1 * 3 * padding), (1 * padding) , width + (-1 * 3 * padding), height + (-1 * 1 * padding));
Paint paint = new Paint();
paint.setColor(Color.WHITE);
canvas.drawRect(0, 0, width, height, paint);
paint.setAlpha(64);
canvas.drawBitmap(sourceBitmap, srcRect, desrect1, paint);
paint.setAlpha(128);
canvas.drawBitmap(sourceBitmap, srcRect, desrect2, paint);
paint.setAlpha(255);
canvas.drawBitmap(sourceBitmap, srcRect, desrect3, paint);
return resultBitmap;
}