你好,游客 登录 注册 搜索
背景:
阅读新闻

Android游戏编程之基本图形编程

[日期:2013-02-06] 来源:Linux社区  作者:wangdong [字体:大 中 小]

现在看看测试代码:

package org.example.ch04_Android_basics;

import java.io.IOException;
import java.io.InputStream;

import android.app.Activity;
import android.content.Context;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

public class BitmapTest extends Activity {
 class RenderView extends View{
  Bitmap bob565;
  Bitmap bob4444;
  Rect dst = new Rect();
 
  public RenderView(Context context){
   super(context);
   
   try{
    AssetManager assetManager = context.getAssets();
    InputStream inputStream = assetManager.open("bobrgb888.png");
    bob565 = BitmapFactory.decodeStream(inputStream);
    inputStream.close();
    Log.d("BitmapText",
      "bobrgb888.png format: " + bob565.getConfig());
   
    inputStream = assetManager.open("bobargb8888.png");
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inPreferredConfig = Bitmap.Config.ARGB_4444;
    bob4444 = BitmapFactory
      .decodeStream(inputStream, null, options);
    inputStream.close();
    Log.d("BitmapText",
      "bobargb8888.png format: " + bob4444.getConfig());
   }catch(IOException e){
    // silently ignored, bad coder monkey, baaad!
   }finally{
    // we should really close our input streams here.
   }
  }
 
  protected void onDraw(Canvas canvas){
   dst.set(50, 50, 350, 350);
   canvas.drawBitmap(bob565, null, dst, null);
   canvas.drawBitmap(bob4444, 100, 100, null);
   invalidate();
  }
 }

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);

 

// 将窗口设置为全屏
  requestWindowFeature(Window.FEATURE_NO_TITLE);
  getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
    WindowManager.LayoutParams.FLAG_FULLSCREEN);
  setContentView(new RenderView(this));
 }
}

运行效果:

linux
相关资讯       Android编程  Android游戏编程 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款