【问题标题】:Android: Creating a high quality thumbnail imageAndroid:创建高质量的缩略图
【发布时间】:2013-12-10 07:59:27
【问题描述】:

我在为拍摄的图像创建高质量缩略图时遇到了一些困难。我知道网上有很多sn-p代码和教程来创建缩略图。我试过了,但我的问题是我无法生成高质量的缩略图。输出总是像素化的。任何建议,图书馆或链接家伙?提前致谢。

I tried this one 但它的质量也很差。

 public static Bitmap scaleBitmap(Bitmap bitmap, int wantedWidth, int wantedHeight) {
        Bitmap output = Bitmap.createBitmap(wantedWidth, wantedHeight, Config.ARGB_8888);
        Canvas canvas = new Canvas(output);
        Matrix m = new Matrix();

        m.setScale((float) wantedWidth / bitmap.getWidth(), (float) wantedHeight / bitmap.getHeight());

        canvas.drawBitmap(bitmap, m, new Paint());

        return output;
    }

【问题讨论】:

  • 您在哪个语言版本和哪个平台上开发?您是否正在开发向 Android 浏览器提供内容的 Web 应用程序?
  • 我在 android 中使用 java。我有这个带有自定义摄像头的原生 android 应用程序,我想为我捕获的图像创建一个缩略图。
  • 向我们展示一些您尝试过的代码。我可以只使用 android api 定义漂亮的缩略图。
  • @Snicolas ,我发布了一些代码。好心检查。 :)

标签: java android image scale


【解决方案1】:

使用RapidDecoder 库。很简单,如下:

import rapid.decoder.BitmapDecoder;
...
Bitmap bitmap = BitmapDecoder.from(getResources(), R.drawable.image)
                             .scale(width, height)
                             .useBuiltInDecoder(true)
                             .decode();

如果您想缩小 50% 以下并获得 HQ 结果,请不要忘记使用内置解码器。

【讨论】:

    【解决方案2】:

    你试过了吗,

    Bitmap src = Thumbnails.getThumbnail(getContentResolver(), ContentUris.parseId(sourceUri), Thumbnails.MINI_KIND, options);
    

    【讨论】:

      【解决方案3】:

      试试这个

      Bitmap ThumbImage =ThumbnailUtils.extractThumbnail(BitmapFactory.decodeFile(imagePath),THUMBSIZE, THUMBSIZE);
      

      此实用程序可从 API_LEVEl 8 获得。[来源]

      【讨论】:

        猜你喜欢
        • 2014-04-07
        • 2011-10-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-10-11
        • 2015-04-23
        • 2012-02-21
        • 1970-01-01
        相关资源
        最近更新 更多