我在繪製ImageView時有一個。當從onCreate()繪製一切OK時,但是當我通過按下按鈕(函數「qwe」)繪製出錯時。哪裏不對?與Android的麻煩
package com.example.asd;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
public class MainActivity extends Activity {
Bitmap myBitmap;
Canvas myCanvas;
ImageView myImageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
config();
}
public void config()
{
myBitmap=Bitmap.createBitmap(500, 500, Bitmap.Config.ARGB_8888);
myCanvas=new Canvas(myBitmap);
myImageView =(ImageView)findViewById(R.id.imageView1);
for(int i=0;i<200;i++)
for(int j=0;j<200;j++)
myBitmap.setPixel(i, j, 0xffffff00);
myImageView.setImageBitmap(myBitmap);
Paint myPaint=new Paint();
myPaint.setColor(0xff000000);
myCanvas.drawLine(10, 10, 190, 190, myPaint);
}
public void qwe(View v)
{ Paint myPaint=null;
myPaint.setColor(0xff000000);
myCanvas.drawLine(190, 10, 190, 10, myPaint);
myImageView.draw(myCanvas);
}
}
和錯誤是? –