以下は、Android用の新しいペインターアプリです。
ただし、以前に描画したオブジェクトは反映されません。(画面をタッチすると形が崩れます)
以前に描画したオブジェクトを反映するために、「Bitmap.createBitmap」メソッドを使用しようとしましたが、機能しません。
私を助けてください。
public class CreativePainterActivity extends Activity {
//
//private MyView vw;
Paint mPaint;
//--Variables to store the current figure info
private float _currentStartX; //where mouse first pressed
private float _currentStartY;
private float _currentEndX; //where dragged to or released
private float _currentEndY;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
setContentView(new MyView(this));
mPaint = new Paint();
mPaint.setAntiAlias(true);
mPaint.setDither(true);
mPaint.setColor(0xFFFFFF00);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeJoin(Paint.Join.ROUND);
mPaint.setStrokeCap(Paint.Cap.ROUND);
mPaint.setStrokeWidth(8);
}
//view class
public class MyView extends View{
private Canvas mCanvas;
private Bitmap mBitmap;
private Paint mBitmapPaint;
Bitmap bm;
//private Paint mBitmapPaint;
public MyView(Context context){
super(context);
//ADDED
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
mBitmap = Bitmap.createBitmap(metrics.widthPixels, metrics.heightPixels, Bitmap.Config.ARGB_8888);
mCanvas = new Canvas(mBitmap);
mBitmapPaint = new Paint(Paint.DITHER_FLAG);
mCanvas.drawColor(0xFFFFFFFF);
bm = BitmapFactory.decodeResource(getResources(),R.drawable.ic_launcher);
}
public void onDraw(Canvas canvas){
//canvas.drawColor(Color.LTGRAY);
canvas.drawBitmap(bm, 0, 0, mBitmapPaint);
canvas.drawLine(_currentStartX, _currentStartY, _currentEndX, _currentEndY, mPaint);
}
//Methods for touch events
public boolean onTouchEvent(MotionEvent event){
if (event.getAction() == MotionEvent.ACTION_DOWN){
_currentStartX=event.getX();
_currentStartY=event.getY();
return true;
}
if(event.getAction() == MotionEvent.ACTION_MOVE){
_currentEndX=event.getX();
_currentEndY=event.getY();
invalidate();
return true;
}
return true;
}
}//end of the class MyView
}//end of the class CreativePainterActivity