首页 > 其他 > 详细

drafwable-旋转

时间:2015-03-21 16:58:55      阅读:276      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!