Android ライブ壁紙 Drawable 描画用 あれこれサンプル
// | |
// Android ライブ壁紙 Drawable 描画用 あれこれサンプル | |
// | |
/**================================== | |
* R.java から Drawable取得 | |
*/ | |
// 取得 | |
private Drawable _image; | |
_image = r.getDrawable(R.drawable.image0); | |
/**================================== | |
*描画 | |
*/ | |
int x =0; | |
int y =0; | |
int w = _image.getIntrinsicWidth();//Drawableの幅取得 | |
int h= _image.getIntrinsicHeight();//Drawableの高さ取得 | |
_image.setBounds(x, y, x + w, y + h);//★必ず呼ぶ | |
_image.setAlpha(255);//アルファ0〜255 | |
_image.draw(c); | |
/**================================== | |
*カラーフィルター 例 | |
*/ | |
//カラーフィルターをかける | |
ColorFilter cf = new PorterDuffColorFilter(Color.BLUE, PorterDuff.Mode.MULTIPLY); | |
_image.setColorFilter(cf); | |
//もしくは | |
_image.setColorFilter(Color.BLUE, PorterDuff.Mode.MULTIPLY); | |
/**================================== | |
* R.java から動的にDrawableを取得 | |
*/ | |
_image = _res.getDrawable(getResources().getIdentifier("ファイル名", "drawable", getPackageName())); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment