使用矩形尺寸裁剪图像

问题描述 投票:0回答:1

我正在尝试裁剪GIF动画,因为我从裁剪GIF的每个位图开始,在裁剪位图后我会将它们存储在ArrayList中但是当我裁剪图像时我有尺寸问题

enter image description here

我得到了什么:

enter image description here

Rect rect = ((GIFCropper) findViewById(R.id.CropView)).getCropRect();
                final String srcPath = path;
                desPath = getDesPath(srcPath, cropIndex);
                GifDecoder gifDecoder = new GifDecoder();
                boolean isSucceeded = gifDecoder.load(path);
                if (isSucceeded) {
                    for (int i = 0; i < gifDecoder.frameNum(); ++i) {
                        croppedBmp = Bitmap.createBitmap(gifDecoder.frame(i), rect.centerY(), rect.centerX(), rect.width(), rect.height());
                        bitmapArrayList.add(croppedBmp);
                    }

                }
java android crop android-bitmap
1个回答
0
投票

首先,您需要确保裁剪器视口正确映射到位图大小

然后改变这个:

Bitmap.createBitmap(gifDecoder.frame(i),rect.centerY(),rect.centerX(),rect.width(),rect.height());

对此:

Bitmap.createBitmap(gifDecoder.frame(i),rect.left,rect.top,rect.width(),rect.height());

© www.soinside.com 2019 - 2024. All rights reserved.