机器人如何扩大与BitmapFactory选项的图像 [英] Android how to scale an image with BitmapFactory Options

查看:195
本文介绍了机器人如何扩大与BitmapFactory选项的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要脱code从SD卡BitmapFactory.de codeFILE(路径选择)的图像。
我也希望是大于2048×2048像素缩小到最多2048×2048(维持的比例)的图像。
得到位图后手动我能做到这一点,但这需要分配除已分配的那些大量的字节。
我应该怎么设置我BitmapFactory.Options反对获得这种效果?
谢谢

I want to decode an image from the SD card with BitmapFactory.decodeFile(path, options).
I also want images that are larger than 2048x2048 pixels to be scaled down to at most 2048x2048 (maintaining the proportions).
I could do this manually after getting the bitmap, but that would require allocating a large amount of bytes in addition to the ones already allocated.
How should i set up my BitmapFactory.Options object to get that effect?
Thanks

推荐答案

使用<一个href="http://developer.android.com/reference/android/graphics/BitmapFactory.Options.html#inSampleSize"相对=nofollow> BitmapFactory.Options.inSampleSize 当您第一次加载你的形象,以获得规模尽可能接近你的目标大小,然后用 Bitmap.createScaledBitmap 扩展到你想要的确切大小。

Use BitmapFactory.Options.inSampleSize when you first load your image to get the size as close as possible to your target size, then use Bitmap.createScaledBitmap to scale to the exact size you want.

有一些$ C $下这这个答案

There's some code for this in this answer.

这篇关于机器人如何扩大与BitmapFactory选项的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆