###概要
Androidアプリで、作成したpng画像をBitmapで表示する処理を書いたのですが、実機のデバッグで起動すると、
01-28 16:25:44.818 8951-8951/? E/Trace﹕ error opening trace file: No such file or directory (2)
と表示され、画面が真っ白のままになっていました。
###コード
Index.java
lang
1package jp.co.hokkaido.nakafurano.hideo.kodama.rapidrescue; 2 3import android.app.Activity; 4import android.os.Bundle; 5import android.view.Window; 6import android.view.WindowManager; 7 8/** 9 * Created by kodamahideo on 2016/09/08. 10 */ 11public class Index extends Activity { 12 13 @Override 14 protected void onCreate(Bundle bundle){ 15 super.onCreate(bundle); 16 17 getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); 18 getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); 19 requestWindowFeature(Window.FEATURE_NO_TITLE); 20 setContentView(new IndexView(this)); 21 } 22}
IndexView.java
lang
1package jp.co.hokkaido.nakafurano.hideo.kodama.rapidrescue; 2 3import android.app.Activity; 4import android.content.Intent; 5import android.content.res.Resources; 6import android.graphics.Bitmap; 7import android.graphics.BitmapFactory; 8import android.graphics.Canvas; 9import android.graphics.Point; 10import android.graphics.Rect; 11import android.view.Display; 12import android.view.MotionEvent; 13import android.view.View; 14import android.widget.ImageView; 15 16/** 17 * Created by kodamasatoru on 2016/09/08. 18 */ 19public class IndexView extends View { 20 21 private final static int 22 W = 480, 23 H = 800; 24 25 private Graphics g; 26 private Bitmap bmp; 27 private int DH; 28 29 public IndexView(Activity activity) { 30 super(activity); 31 32 Display display = activity.getWindowManager().getDefaultDisplay(); 33 Point p = new Point(); 34 display.getSize(p); 35 int dh = W*p.y/p.x; 36 this.DH = dh; 37 38 g = new Graphics(W,dh); 39 g.setOrigin(0,(dh-H)/2); 40 } 41 42 @Override 43 protected void onDraw(Canvas canvas){ 44 super.onDraw(canvas); 45 //TODO 背景描画 46 Resources r = getResources(); 47 bmp = BitmapFactory.decodeResource(r,R.drawable.title); 48 g.drawBitmap(bmp,0,0); 49 int w = bmp.getWidth(); 50 int h = bmp.getHeight(); 51 Rect src = new Rect(0, 0, w, h); 52 // 描画先の矩形イメージ 53 Rect dst = new Rect(0, 0, 480, DH); 54 g.drawBitmap(bmp,src,dst); 55 56 } 57 58 @Override 59 public boolean onTouchEvent(MotionEvent event){ 60 int touchAction = event.getAction(); 61 if (touchAction == MotionEvent.ACTION_DOWN){ 62 getContext().startActivity(new Intent(getContext(),Main.class)); 63 } 64 65 return true; 66 } 67}
Graphics.java
lang
1 2package net.npaka.puzzlegame; 3import android.graphics.Bitmap; 4import android.graphics.Canvas; 5import android.graphics.Paint; 6import android.graphics.Paint.FontMetrics; 7import android.graphics.Rect; 8 9//グラフィックス(9) 10public class Graphics { 11 private Paint paint; //ペイント 12 private Bitmap bmp; //ビットマップ 13 private Canvas canvas; //キャンバス 14 private int originX;//原点X 15 private int originY;//原点Y 16 17 //コンストラクタ 18 public Graphics(int w, int h) { 19 bmp = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); 20 canvas = new Canvas(bmp); 21 paint = new Paint(); 22 paint.setAntiAlias(true); 23 } 24 25 //ビットマップの取得 26 public Bitmap getBitmap() { 27 return bmp; 28 } 29 30 //描画原点の指定 31 public void setOrigin(int x, int y) { 32 canvas.translate(x, y); 33 originX = x; 34 originY = y; 35 } 36 37 //描画原点のX座標の取得 38 public int getOriginX() { 39 return originX; 40 } 41 42 //描画原点のY座標の取得 43 public int getOriginY() { 44 return originY; 45 } 46 47 //色の指定 48 public void setColor(int color) { 49 paint.setColor(color); 50 } 51 52 //フォントサイズの指定 53 public void setTextSize(int fontSize) { 54 paint.setTextSize(fontSize); 55 } 56 57 //フォントメトリックスの取得 58 public FontMetrics getFontMetrics() { 59 return paint.getFontMetrics(); 60 } 61 62 //文字幅の取得 63 public int measureText(String string) { 64 return (int)paint.measureText(string); 65 } 66 67 //塗り潰し矩形の描画 68 public void fillRect(int x, int y, int w, int h) { 69 if (canvas == null) return; 70 paint.setStyle(Paint.Style.FILL); 71 canvas.drawRect(new Rect(x, y, x+w, y+h), paint); 72 } 73 74 //ビットマップの描画 75 public void drawBitmap(Bitmap bitmap, int x, int y) { 76 if (canvas == null) return; 77 int w = bitmap.getWidth(); 78 int h = bitmap.getHeight(); 79 Rect src = new Rect(0, 0, w, h); 80 Rect dst = new Rect(x, y, x+w, y+h); 81 canvas.drawBitmap(bitmap, src, dst, null); 82 } 83 84 //ビットマップの描画 85 public void drawBitmap(Bitmap bitmap, Rect src, Rect dst) { 86 if (canvas == null) return; 87 canvas.drawBitmap(bitmap, src, dst, null); 88 } 89 90 //文字列の描画 91 public void drawText(String string, int x, int y) { 92 if (canvas == null) return; 93 canvas.drawText(string, x, y, paint); 94 } 95}
ちなみに、画像の場所は、
app/src/main/res/drawable-nodpi/title.png
です。
どこに問題があるのでしょうか。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/02/05 09:39
2017/02/05 10:40
2017/03/04 02:32