1.图片旋转
private Drawable rotatDrawable(Drawable drawable, float angle){ Matrix matrix = new Matrix(); Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap(); matrix.setRotate(angle); bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); return new BitmapDrawable(bitmap); }
它能够实现旋转,但是图片大小却改变了
方法二:
private Bitmap mHistoryHideButtonBitmap; private Drawable mHistoryHideButtonDrawable; private boolean mHistoryHideButtonSign; private int mHistoryHideButtonBitmapWidth; private int mHistoryHideButtonBitmapHeight; mHistoryHideButtonBitmap = BitmapFactory.decodeResource(getResources(),R.drawable.history_pad_display_bg_normal); mHistoryHideButtonDrawable = getResources().getDrawable(R.drawable.history_pad_display_bg_normal); mHistoryHideButtonBitmapWidth = mHistoryHideButtonBitmap.getWidth() ; mHistoryHideButtonBitmapHeight = mHistoryHideButtonBitmap.getHeight(); private Drawable rotatDrawable(Drawable drawable, float angle){ Matrix matrix = new Matrix(); /* Vanzo:zhangshuli on: Sat, 21 Mar 2015 14:53:54 +0000 * modify for v5 calculator matrix.setRotate(angle); */ matrix.postRotate(angle, mHistoryHideButtonBitmapWidth/2, mHistoryHideButtonBitmapWidth/2); // End of Vanzo: zhangshuli Bitmap bitmap = Bitmap.createBitmap(mHistoryHideButtonBitmap, 0, 0, mHistoryHideButtonBitmapWidth, mHistoryHideButtonBitmapHeight, matrix, true); return new BitmapDrawable(bitmap); }
仍然会缩小
方法三
时间: 2024-11-07 19:20:16