【问题标题】:How to set image on canvas from resource class如何从资源类在画布上设置图像
【发布时间】:2017-04-27 13:21:56
【问题描述】:

我尝试从我在resource.java 上声明的drawable 设置位图图像。当我单击下一步按钮时,它将显示另一个我可以绘制的图像。这是调用它的正确代码吗?

bmp = BitmapFactory.decodeResource(getResources(), Resource.capitalStoke[DrawingActivity.this.position]);

还是要添加?

这是我的资源.java:

public class Resource {

    public static String DRAWING_ALPHABET;
    public static Integer[] capitalStoke;
    Integer[] alphabetCapital;
    Integer[] alphabetSound;
    Integer[] alphabetImage;

    static {
        DRAWING_ALPHABET = "alphabet";
        capitalStoke = new Integer[]{Integer.valueOf(R.drawable.capital_letters_stroke_01),
                                     Integer.valueOf(R.drawable.capital_letters_stroke_02),
                                     Integer.valueOf(R.drawable.capital_letters_stroke_03),};
        }

是否可以使用 bitmapfactory 从这里检索图像?如果可以,我应该怎么做?

【问题讨论】:

    标签: android


    【解决方案1】:

    直接关注这个How to set a bitmap from resource

    在我看来,更好的主意是以通用方式使用它——就像R.id.drawable_1; 这样的常量。您始终可以将以下 id 存储在数组或列表中以进行迭代。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-03-10
      • 1970-01-01
      • 2021-06-12
      • 2019-03-27
      • 2014-01-28
      • 2011-06-24
      • 1970-01-01
      相关资源
      最近更新 更多