【问题标题】:Android Bitmap ScaleAndroid 位图缩放
【发布时间】:2016-07-06 15:54:31
【问题描述】:

我有一个大小为 400x400 的 ImageView。 我想缩放一个纵横比的位图 保持不变,但长边是400!

代码:

selectedImage = BitmapFactory.decodeStream(inputStream);
//Calculate and Scale
selectedImage = Bitmap.createScaledBitmap(selectedImage, X, Y, false);
imageView.setImageBitmap(selectedImage);

示例: 位图的大小为 800x400 --> 位图被缩放 --> 结果是一个大小为 400x200 的位图

【问题讨论】:

  • 不够清楚。无论原始尺寸如何,您是否希望缩放位图的较长边始终为 400?
  • 是的。如果它更小,它会被拉伸

标签: android bitmap scale


【解决方案1】:

试试这个。根据需要设置图像视图的高度和宽度

selectedImage = BitmapFactory.decodeStream(inputStream);
//Calculate and Scale
selectedImage = Bitmap.createScaledBitmap(selectedImage, X, Y, false);
imageView.setScaleType(ScaleType.FIT_XY);  // maintain image dimension to fit in imageview
imageView.setImageBitmap(selectedImage);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-01-03
    • 1970-01-01
    • 2011-06-22
    • 2011-05-04
    • 1970-01-01
    • 1970-01-01
    • 2012-09-30
    • 1970-01-01
    相关资源
    最近更新 更多