簡體   English   中英

如何在Android中將圖像拉直應用到圖像時獲得高質量的裁剪位圖

[英]how to get quality cropped bitmap when straighten applied for imageview in android

我認為它應該是重復的,但對於這個問題我沒有任何解決方案。 我的問題是:

我正在開發一個應用程序,該應用程序具有諸如具有縱橫比的裁切和具有旋轉和拉直的裁切之類的功能。 為此,我正在使用庫。 具有裁切,旋轉和拉直功能,但工作正常,但是我的問題是在調用裁切功能以拉直圖像后導致質量不佳。 我該如何克服這個問題?

這是我用於裁剪的代碼:

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。

嘗試使用:

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。

注意:“矩陣旋轉”方法以正值順時針旋轉,而負值則逆時針旋轉。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM