【问题标题】:How to increase image quality如何提高图像质量
【发布时间】:2016-05-19 11:19:34
【问题描述】:

我在缩小图像时遇到了一点问题。在大分辨率手机上,所有图像看起来都不错,但是当需要在较小的手机上缩小图像时,图像看起来并不流畅。也许有人可以帮助我,缩小缩放后如何提高图像质量。提前致谢。以下是 Note 4 和 S2 手机的一些屏幕截图:

Note 4 Screen Shoot, upscale from 3840x2160 to 4551x2560

S2 Screen Shoot, downscale from 3840x2160 to 1422x800

    Bitmap bitmap;

public void setWallpaper() {

    Bitmap bitmap = BitmapFactory.decodeStream(getResources().openRawResource(R.raw.img_test));

    float screenWidth, screenHeight;
    float bitmap_width = bitmap.getWidth(), bitmap_height = bitmap.getHeight();

    Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    screenWidth = display.getWidth();
    screenHeight = display.getHeight();

    float bitmap_ratio = bitmap_width / bitmap_height;
    float screen_ratio = screenWidth / screenHeight;
    int bitmapNewWidth, bitmapNewHeight;

    if (screen_ratio > bitmap_ratio) {
        bitmapNewWidth = (int) screenWidth;
        bitmapNewHeight = (int) (bitmapNewWidth / bitmap_ratio);
    } else {
        bitmapNewHeight = (int) screenHeight;
        bitmapNewWidth = (int) (bitmapNewHeight * bitmap_ratio);
    }

    bitmap = Bitmap.createScaledBitmap(bitmap, bitmapNewWidth, bitmapNewHeight, true);

    try {
        WallpaperManager myWallpaperManager = WallpaperManager.getInstance(getApplicationContext());
        myWallpaperManager.setBitmap(bitmap);
        Toast.makeText(getApplicationContext(), "Set wallpaper successfully!", Toast.LENGTH_SHORT).show();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

【问题讨论】:

    标签: android image resize scale wallpaper


    【解决方案1】:

    使用以下方法缩放图像

    Options options = new BitmapFactory.Options();
    options.inScaled = false;
    Bitmap source = BitmapFactory.decodeResource(a.getResources(), path, options);
    

    【讨论】:

    • 我已经尝试过了,但不幸的是图像看起来一样,就像没有抗锯齿一样。
    猜你喜欢
    • 1970-01-01
    • 2019-01-30
    • 2020-04-21
    • 1970-01-01
    • 1970-01-01
    • 2011-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多