多次旋转位图使图像模糊如何避免它

时间:2017-01-18 13:47:04

标签: android bitmap rotation

我希望像用户点击旋转按钮一样旋转图像。下面的代码使图像正确旋转,但我的图像变得模糊。

我一直在使用以下代码:

 backLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            for(int i=0;i<selectedImageList.size();i++) {

                BitmapFactory.Options bmOptions = new BitmapFactory.Options();
                Bitmap scaledBitmap = BitmapFactory.decodeFile(selectedImageList.get(i), bmOptions);
                Matrix matrix=new Matrix();
                matrix.preRotate(0);
                Bitmap rotatedBitmap = Bitmap.
                        createBitmap(scaledBitmap , 0, 0, scaledBitmap .getWidth(), scaledBitmap .getHeight(), matrix, true);

                File file=Utility.createFileFromBitmap(rotatedBitmap);
                File oldFile=new File(selectedImageList.get(i));
                LogUtil.error("Deleted Name",oldFile.getAbsolutePath()+"-->"+file.getAbsolutePath());
                oldFile.delete();
                itemList.set(selectedImages.get(i),file.getAbsolutePath());
                selectedImageList.set(i,file.getAbsolutePath());
                mSnapRecyclerAdapter.notifyDataSetChanged();


            }

Below ll be the image

1 个答案:

答案 0 :(得分:0)

Matrix matrix = new Matrix();
imageView.setScaleType(ImageView.ScaleType.MATRIX);   //required
matrix.postRotate((float) angle, pivotX, pivotY);
imageView.setImageMatrix(matrix);

/

@Override
public void onClick(View v)
{                  
    imageView.setRotation(imageView.getRotation() + 90);
}