【Android】drawBitmapから2種類
|
android.graphics.CanvasのdrawBitmapについて
drawBitmapは6つあって
・drawBitmap(int[] colors, int offset, int stride, float x, float y, int width, int height, boolean hasAlpha, Paint paint)
・drawBitmap(Bitmap bitmap, Matrix matrix, Paint paint)
・drawBitmap(int[] colors, int offset, int stride, int x, int y, int width, int height, boolean hasAlpha, Paint paint)
・drawBitmap(Bitmap bitmap, Rect src, RectF dst, Paint paint)
・drawBitmap(Bitmap bitmap, float left, float top, Paint paint)
・drawBitmap(Bitmap bitmap, Rect src, Rect dst, Paint paint) がある。
今のところ使っているのは5番目と6番目なので、使い方をメモします。
・drawBitmap(Bitmap bitmap, float left, float top, Paint paint)について
bitmapをそのまま描画する。引数には左上の座標を指定する。
簡単だが、拡大縮小できない。
・drawBitmap(Bitmap bitmap, Rect src, Rect dst, Paint paint)について
bitmapの指定した部分を切り出して、指定した大きさに拡大縮小する。
※Rectクラスは左上の座標と、右下の座標を指定する。
↑Rect(int left, int top, int right, int bottom)
Rectの大きさが固定の場合は
Rect.offsetTo(int newLeft, int newTop)を使ってRectを平行移動させると、
画像を多く貼り付けるときに便利。
|