【问题标题】:how to use bitmap/drawable instead of color constants in android如何在android中使用位图/可绘制而不是颜色常量
【发布时间】:2016-01-02 06:47:51
【问题描述】:

目前我正在开发一个使用 Particle 的项目,该项目适用于颜色常量,但我想改用可绘制/位图。

DATA = new int[]{16777215, -2130706433, 16777215};

然后使用DATA 传递到创建位图。

BMP = Bitmap.createBitmap(DATA, 0, 5, 1, 1, Bitmap.Config.ARGB_8888);

我应该如何使用可绘制资源并传递它来创建位图?

我已经尝试过context.getResources(),也尝试过上课

public class App extends Application {
    private static Context mContext;

    @Override
    public void onCreate() {
        super.onCreate();
        mContext = this;
    }

    public static Context getContext() {
        return mContext;
    }
}

并使用App.getContext().getResources(),但它不起作用。我正在尝试在抽象静态类中创建位图。

【问题讨论】:

标签: java bitmap android-canvas particles


【解决方案1】:

使用位图工厂方法解码可绘制资源,如

Bitmap bmp = BitmapFactory.decodeResource(context.getResources(), R.drawable.your_resource);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-22
    • 2013-01-12
    • 1970-01-01
    • 1970-01-01
    • 2012-12-08
    • 1970-01-01
    相关资源
    最近更新 更多