问题描述
在我开始,我想你告诉我使用的是非常不正确的方法为撤消操作。
我有一个绘图应用程序,这将节省您每次在视图中绘制笔画,而当你退出该应用程序的最终图像将被复制到文件夹和其他人将被删除。
Before I start I would like you to tell that I am using a very improper method for the "undo" operation.I have a drawing app which will save each strokes you draw on the view, and when you exit the app the final image will be copied to a folder and others will be deleted.
现在,当您在视图中绘制笔画,每个文件都将被保存在一个临时。夹和每个文件的路径将被插入到数据库中,这是为执行撤消操作。当用户点击撤销,最后插入的值(路径)将被删除,接下来的路径将被quired。
我的计划是使用此路径来绘制视图上的形象,让每一个用户的撤消的时间,保存在数据库中的最后一个路径将被删除,接下来的道路将采取
Now when you draw strokes on the view, each file will be saved in a temp. folder and the path of each file will be inserted to the database, this is to implement the undo operation. When the user clicks for undo, the last inserted value(path) will be deleted and the next path will be quired.My plan is to use this path to draw the image on the view, so each time the user 'undo's , the last path saved in the database will be deleted and the next path will be taken.
希望你得到了我的想法..!
现在我的问题是,我不能够将图像绘制到视图,
我有一个绘制斯托克斯自定义视图。
Hope you got my idea..!Now my issue is , I am not able to draw the image to the view,I have a custom view which draws the stokes.
查看
public class MyView extends View {
private static final float MINP = 0.25f;
private static final float MAXP = 0.75f;
private Bitmap mBitmap;
private Paint mBitmapPaint;
public MyView(Context c) {
super(c);
mPath = new Path();
mBitmapPaint = new Paint(Paint.DITHER_FLAG);
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
mCanvas = new Canvas(mBitmap);
mCanvas.drawColor(Color.BLACK);
}
@Override
protected void onDraw(Canvas canvas) {
try{
new SaveFileThread().execute(null); //------->save strokes as files
Log.i("In ondraw log", "Wow "+filename);
if(undoflag=="undo" && nextp!="haha"){
String pat=UnDo();
if(pat!=null){
if(pat==filename){ pat=UnDo(); Log.i("undo called twice", "not again");}
else{
// Bitmap nbmp=LoadBMPsdcard(pat);
//render the SD card image
// canvas.drawBitmap(nbmp, 0, 0, null);
}
}
//the parent onDraw() method.
// super.onDraw(canvas);
}
//canvas.drawColor(000000);
canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);
canvas.drawPath(mPath, mPaint);
}catch(Exception e){
e.printStackTrace();
}
}
private float mX, mY;
private static final float TOUCH_TOLERANCE = 4;
private void touch_start(float x, float y) {
mPath.reset();
mPath.moveTo(x, y);
mX = x;
mY = y;
}
private void touch_move(float x, float y) {
float dx = Math.abs(x - mX);
float dy = Math.abs(y - mY);
if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) {
mPath.quadTo(mX, mY, (x + mX)/2, (y + mY)/2);
mX = x;
mY = y;
}
}
private void touch_up() {
mPath.lineTo(mX, mY);
// commit the path to our offscreen
mCanvas.drawPath(mPath, mPaint);
// kill this so we don't double draw
mPath.reset();
}
@Override
public boolean onTouchEvent(MotionEvent event) {
float x = event.getX();
float y = event.getY();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
touch_start(x, y);
invalidate();
break;
case MotionEvent.ACTION_MOVE:
touch_move(x, y);
invalidate();
break;
case MotionEvent.ACTION_UP:
touch_up();
invalidate();
break;
}
return true;
}
}
我有一个线程,将做节能,
我怎样才能从SD卡这一观点绘制图像。
I have a thread that will do the saving,How can I draw an image from the SD card to this view.
任何一个可以建议我更好的想法做到这一点。
如果你把不同的想法这将是一个很大的帮助,如果你有一些样本code。
Can any one suggest me any better ideas to do this.It would be a great help if you have some sample code if you bring a different idea.
在此先感谢
快乐编码
推荐答案
这code是工作在我的绘画应用程序。
This code is working in my drawing app..
private Slate mSlate;
private TiledBitmapCanvas mTiledCanvas;
public void clickUndo(View unused) {
mSlate.undo();
}
public void undo() {
if (mTiledCanvas == null) {
Log.v(TAG, "undo before mTiledCanvas inited");
}
mTiledCanvas.step(-1);
invalidate();
}
这篇关于撤消绘图应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!