2012-05-23 61 views
0

我做了一個應用程序,它通常用於繪製線數字。假設我做了一個square.now我想保存它,當我再次開始我的應用程序,所以我必須看到方可能。 這裏是我的代碼如何在繪製時在android中保存活動

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    // Set full screen view 
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
            WindowManager.LayoutParams.FLAG_FULLSCREEN); 
    requestWindowFeature(Window.FEATURE_NO_TITLE); 
    DrawView drawView = new DrawView(this, null); 
    setContentView(drawView); 
    drawView.requestFocus(); 

} 
@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // TODO Auto-generated method stub 
    menu.add(0,1,1,"RED").setShortcut('3', 'C'); 
    menu.add(0,2,2,"GREEN"); 
    menu.add(0,3,3,"BLUE"); 
    menu.add(0,4,4,"Erase"); 
    return super.onCreateOptionsMenu(menu); 
} 

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    // TODO Auto-generated method stub 
    switch(item.getItemId()) 
    { 
    case 1: 
     first(x,y,z); 
     break; 

    case 4: 
     DrawView.second(); 
     break; 
    } 
    return super.onOptionsItemSelected(item); 
} 

public List<Integer> first(int x2, int y2, int z2) { 
    // TODO Auto-generated method stub 

    x2=100;y2=150;z2=200; 
    al.add(x2);al.add(y2);al.add(z2); 
    return al; 

} 

}

public DrawView(Context context, AttributeSet attrs) { 
    super(context, attrs); 
    list1 = d.first(a,b,c); 
    paint.setAntiAlias(true); 
    paint.setColor(Color.rgb(list1.get(0),list1.get(1),list1.get(2))); 
    paint.setStyle(Paint.Style.STROKE); 
    paint.setStrokeJoin(Paint.Join.ROUND); 
    paint.setStrokeWidth(5f); 
    } 

    @Override 
    protected void onDraw(Canvas canvas) { 
    canvas.drawPath(path, paint); 
    } 

    @Override 
    public boolean onTouchEvent(MotionEvent event) { 
    float eventX = event.getX(); 
    float eventY = event.getY(); 

    switch (event.getAction()) { 
     case MotionEvent.ACTION_DOWN: 
     path.moveTo(eventX, eventY); 
     return true; 
     case MotionEvent.ACTION_MOVE: 
     case MotionEvent.ACTION_UP: 
     path.lineTo(eventX, eventY); 
     break; 
     default: 
     return false; 
    } 

    // Schedules a repaint. 
    invalidate(); 
    return true; 
    } 

static void second() { 
    // TODO Auto-generated method stub 
    erase(paint); 
} 

private static void erase(Paint paint2) { 
    // TODO Auto-generated method stub 
    paint2.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); 
} 

}

回答

0

Save your canvas to a jpg image,那麼當你開始Activity,檢查是否有圖像存在。如果是,load it and draw on it,否則在空畫布上繪製。

+0

如果我想存儲在我的手機畫廊那麼我應該給路徑的價值。 – sachit

+0

http://stackoverflow.com/questions/9076050/how-to-paint-on-an-image-and-save-the-image-to-phone-gallery-in-android –

+0

請自行搜索。在詢問任何事情之前,你會發現許多對你有幫助的事情。 –

相關問題