简体   繁体   English

如何从资源类在画布上设置图像

[英]How to set image on canvas from resource class

I try to set bitmap image from drawable that i declare on resource.java. 我尝试从我在resource.java上声明的drawable设置位图图像。 When i click next button,it will show another image that i can draw. 当我单击下一步按钮时,它将显示另一幅我可以绘制的图像。 Is this right code to call it? 这是正确的代码吗?

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

or anymore to add? 还是要添加?

this is my resource.java: 这是我的resource.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),};
        }

is that possible to retrieve image from here using bitmapfactory?if possible,how should i do it? 是否可以使用bitmapfactory从此处检索图像?如果可能,该怎么办?

It's right following to this How to set a bitmap from resource . 正确遵循此方法如何从resource设置位图

In my opinion better idea is to use it in common way - just constants like R.id.drawable_1; 在我看来,更好的主意是使用通用方式-就像R.id.drawable_1;这样的R.id.drawable_1; . You can always store followings ids in array or list to iterate. 您始终可以将跟随ID存储在数组或列表中以进行迭代。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM