Android-圖片裁剪/旋轉/縮放

1.系統裁剪

    
    // 選擇圖片,裁剪
    public void crop(View view) {
        startActivityForResult(new Intent(Intent.ACTION_PICK,
            MediaStore.Images.Media.EXTERNAL_CONTENT_URI)
            .putExtra("crop", "true")
            .putExtra("output", Uri.fromFile(new File("/sdcard/!temp.jpg")))
            ,1);
            
        // 系統選擇圖片還可用new Intent(Intent.ACTION_GET_CONTENT).setType(image/*)
        // 系統相機可用new Intent(MediaStore.ACTION_IMAGE_CAPTURE).putExtra("output", xx);
    }
    
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
        if (resultCode != RESULT_OK) return;
        imageView.setImageBitmap(BitmapFactory.decodeFile("/sdcard/!temp.jpg"));
    }
    

2.旋轉縮放


     @Override
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {        
        // 旋轉
        Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
        Matrix matrix = new Matrix();
        matrix.setRotate(progress);
        imageView.setImageBitmap(Bitmap.createBitmap(bitmap,0,0,
                        bitmap.getWidth(),bitmap.getHeight(),matrix,true));
        
        // 縮放
        imageView.setLayoutParams(new RelativeLayout.LayoutParams(progress,progress));
    }

簡書: http://www.lxweimin.com/p/26a17eeed5b8
CSDN博客: http://blog.csdn.net/qq_32115439/article/details/56278330
GitHub博客:http://lioil.win/2017/02/21/ImageView.html
Coding博客:http://c.lioil.win/2017/02/20/ImageView.html

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容