どうも、69です。
今日はイメージ・画像の描画です。
用意するものは
ImageEx.java
ImageView.java
表示させる画像(今回はandroid.pngとking.pngがあります)
です。
Androidでは画像は「PNG」形式です。
では↓
ImageEx.javaは省略です。
今までに作った[~Ex]の~を変えればOKです。
*****ImageView.java**********************************
package info.webry.at.androidid.imageex;
import android.content.res.Resources;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Rect;
import android.view.View;
public class ImageView extends View{
private Bitmap image,images;
public ImageView(Context context){
super(context);
setBackgroundColor(Color.WHITE);
Resources r=context.getResources();
image=BitmapFactory.decodeResource(
r,R.drawable.android);
images=BitmapFactory.decodeResource(
r,R.drawable.king);
}
@Override
protected void onDraw(Canvas canvas){
canvas.drawBitmap(image, 100,0,null);
canvas.drawBitmap(images,-100,0,null);
int w=image.getWidth();
int h=image.getHeight();
Rect src=new Rect(0,0,w,h);
Rect dst=new Rect(0,200,w*2,200+h*2);
canvas.drawBitmap(image, src,dst, null);
}
}
****************************************************
解説は例のごとく、次回。
その前にひとつ。
画像は[ImageEx(プロジェクト名)]-[rec]-[drawable-nodpi(なかったら作って下さい。)]の中に置いておきます。
リソースフォルダ(rec以下)はいくつかの種類があり、通常は[drawable-nodpi]に保存します。
おしまい。
0 件のコメント:
コメントを投稿