Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
202 views
in Technique[技术] by (71.8m points)

java - Crop Area not showing correctly

Hi I am using MianaCropView for give the possibility to my users to crop their images before uploading them . Everythings works fine when its about the result cropped the problem come from the preview showed to users before uploading . I give the possibility to users to crop their image in different aspect ratio from (1:1 to 16:9) .

When the user chose a Scale shadow appears to show witch part of the image will remain and witch part will be cropped (Here an example of a image with 16:9 Scale)

The problem its when I use 1.91:1 the preview doesnt match the result and can give a missrepresentaion of the final image to the user . Here's the preview who's show to the user and here the real result . I need the preview to match the real result .

How can I fix that ?

Here the my code to uptade the cropeArea

private void updateCropArea() {
    int width = getMeasuredWidth();
    int height = getMeasuredHeight();
    if (width == 0 || height == 0) {
        return;
    }
    //compute cropArea
    float left, rigth, top, bottom;
    float finalWidth = 0;
    float finalHeight = 0;
    switch (mCropType) {
        case SQUARE:
            finalWidth = finalHeight = width < height ? width : height;
            break;
    The problem is here :    case SCALE_1_91_1:
            finalHeight = height;

            finalWidth = finalHeight *  1.91f/1;
            break;
        case SCALE_2_3:
            finalHeight = height;
            finalWidth = finalHeight * 2 / 3;
            break;
        case SCALE_3_4:
            finalHeight = height;
            finalWidth = finalHeight * 3 / 4;
            break;
        case SCALE_3_2:
            finalWidth = width;
            finalHeight = finalWidth * 2 / 3;
            break;
        case SCALE_4_3:
            finalWidth = width;
            finalHeight = finalWidth * 3 / 4;
            break;
        case SCALE_4_5:
            finalHeight = height;
            finalWidth = finalHeight * 4 / 5;
            break;
        case SCALE_16_9:
            finalWidth = width;
            finalHeight = finalWidth * 9 / 16;
            break;

    }
    left = (width - finalWidth) * 0.5f;
    top = (height - finalHeight) * 0.5f;
    rigth = left + finalWidth;
    bottom = top + finalHeight;

    RectF cropArea = new RectF(left, top, rigth, bottom);
    mDisplayHelper.setCropArea(cropArea);
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...