我目前正在学习android位映射,而且我有图像,我要加载两次,但应用程序崩溃,我看不出我的问题是什么。
我仔细检查了图像的名称和位置,这不应该是我的问题
任何建议都有帮助。
这是我的代码
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("bob.png");
bob565 = BitmapFactory.decodeStream(inputStream);
inputStream.close();
Log.d("Bitmap Test", "bob.png format:"+ bob565.getConfig());
inputStream = assetManager.open("bob.png");
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_4444;
bob4444 = BitmapFactory
.decodeStream(inputStream , null , options);
inputStream.close();
Log.d("Bitmap test", "bob.png format:" + bob4444.getConfig());
}catch(IOException e){
//silently ignored
}finally{
// close streams
}
}
@Override
protected void onDraw(Canvas canvas){
canvas.drawRGB(0,0,0);
dst.set(50,50,350,350);
canvas.drawBitmap(bob565,null,dst,null);
canvas.drawBitmap(bob4444,100,100,null);
invalidate();
}
}
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(new RenderView(this));
}
}