【问题标题】:Image Processing on Custom ImageView and saving the modified image自定义 ImageView 上的图像处理并保存修改后的图像
【发布时间】:2011-05-20 14:14:10
【问题描述】:

我正在使用自定义 ImageView。在它的 onDraw 中,我使用画布做一些处理,就像画线,基于用户触摸的位图。

为了在用户想要保存图像时保存生成的快照,我们使用了 drawingCache

imageView.setDrawingCacheEnabled(true;
Bitmap.createBitmap(imageView.getDrawingCache(), 0, 0, 
       imageView.getHeight(), imageView.getWidth(),
       matrix, true).compress(CompressFormat.JPEG, 95,
       new FileOutputStream(file));

当然,当用户按下保存时,我可以使用它来获取实际图像,但图像不包含对 imageView 所做的任何处理。

Bitmap bmp = ((BitmapDrawable)imageView.getDrawable()).getBitmap();

Bitmap.createBitmap(bmp, 0, 0, 
        bmp.getWidth(), bmp.getHeight(),
        matrix, true).compress(CompressFormat.JPEG, 95,
                    new FileOutputStream(file));

问题: 保存的图像大小是全屏的 imageView 的大小,但取决于设备。对于较小屏幕尺寸的手机,它会降至 240 X 320。

问题:

一个。无论设备屏幕尺寸如何,是否可以获得合适尺寸的图像?

b.是否可以直接对 Custom ImageView 中使用的 Image 进行图像处理?

感谢期待!

有什么想法吗?

【问题讨论】:

    标签: android android-imageview


    【解决方案1】:

    也许另一种方法是使用 Canvas 类来进行一些绘图和图像显示:javadoc: android.graphics.Canvas

    当图像需要经常“刷新”时,ImageView 类不是最好的。

    如果您决定坚持使用 ImageView,请不要使用 ImageView 的尺寸创建位图。保留图像的纵横比,并根据您需要的大尺寸组成位图。 imageView 将缩小它(如果需要)以适应屏幕。

    【讨论】:

      【解决方案2】:

      你可以使用

          Bitmap.createScaledBitmap(Bitmap b, int newWidth, int newHieght, boolean filter);
      

      并从资源使用中获取位图

           Bitmap image = BitmapFactory.decodeResource(..)
      

      你可以使用

          ImageView.setImageBitmap(Bitmap bm)
      

      将新的位图设置为图像视图

      【讨论】:

      • 我猜你没有得到这个问题。它不是关于缩放图像和显示,而是相反
      猜你喜欢
      • 2019-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-18
      相关资源
      最近更新 更多