我认为应该重复,但我没有得到任何解决方案。我的问题是:
我正在开发一个应用程序,它具有像纵横比的裁剪和旋转和矫直裁剪等功能。因为我正在使用this库。特色裁剪,旋转和拉直工作正常但我的问题是在调用裁剪功能后拉直图像然后结果没有良好的质量。我该如何克服这个问题?
这是我用于裁剪的代码:
private Bitmap getCurrentDisplayedImage() {
Bitmap result = Bitmap.createBitmap(mImageView.getWidth(), mImageView.getHeight(), Bitmap.Config.RGB_8888);
Canvas c = new Canvas(result);
mImageView.draw(c);
return result;}
// Get the scale factor between the actual Bitmap dimensions and the
// displayed dimensions for width.
float actualImageWidth = mCurrentDisplayedBitmap.getWidth();
float displayedImageWidth = displayedImageRect.width();
float scaleFactorWidth = actualImageWidth / displayedImageWidth;
// Get the scale factor between the actual Bitmap dimensions and the
// displayed dimensions for height.
float actualImageHeight = mCurrentDisplayedBitmap.getHeight();
float displayedImageHeight = displayedImageRect.height();
float scaleFactorHeight = actualImageHeight / displayedImageHeight;
// Get crop window position relative to the displayed image.
float cropWindowX = Edge.LEFT.getCoordinate() - displayedImageRect.left;
float cropWindowY = Edge.TOP.getCoordinate() - displayedImageRect.top;
float cropWindowWidth = Edge.getWidth();
float cropWindowHeight = Edge.getHeight();
// Scale the crop window position to the actual size of the Bitmap.
float actualCropX = cropWindowX * scaleFactorWidth;
float actualCropY = cropWindowY * scaleFactorHeight;
float actualCropWidth = cropWindowWidth * scaleFactorWidth;
float actualCropHeight = cropWindowHeight * scaleFactorHeight;
// Crop the subset from the original Bitmap.
Bitmap croppedBitmap = Bitmap.createBitmap(mCurrentDisplayedBitmap, (int) actualCropX, (int) actualCropY, (int) actualCropWidth, (int) actualCropHeight);
return croppedBitmap;}
我用谷歌搜索,我尝试了很多方法,但没有找到更好的解决方案。
如果有人有想法请帮助我。
感谢Adavance。
答案 0 :(得分:0)
尝试使用:
Bitmap.createBitmap(Bitmap bitmap, int xStart, int yStart, int xSize, int ySize, Matrix matrix, boolean render)
并将render设置为true。你也可以选择应用一个矩阵来处理旋转和调整大小,如下所示:
Matrix matrix = new Matrix();
matrix.postScale(float xScale, float yScale);
matrix.postRotate(int degrees);
否则只需将Matrix设置为null。
注意:矩阵旋转方法顺时针旋转正值,逆时针旋转负值。