码迷,mamicode.com
首页 > 其他好文 > 详细

drafwable-旋转

时间:2015-03-21 16:59:48      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:

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);
    } 

仍然会缩小

方法三

 

drafwable-旋转

标签:

原文地址:http://www.cnblogs.com/zhangshuli-1989/p/4355757.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!