Ahoj mozna to chci delat blbe ale chci se zeptat jak z canvasu ulozit pro pozdejsi pouziti kvuli obnove mista do puvodniho stavu.
class Panel extends SurfaceView implements SurfaceHolder.Callback {
CanvasControler canvascontroler=null;
LastCanvasFragment lastFragment=null;
public Panel(Context context, AttributeSet attrs) {
super(context, attrs);
getHolder().addCallback(this);
canvascontroler = new CanvasControler(getHolder(), this);
setFocusable(true);
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
// TODO Auto-generated method stub
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
// TODO Auto-generated method stub
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
// TODO Auto-generated method stub
}
public void DrawImage(float x, float y, int imageId)
{
Canvas canvas=null;
if(lastFragment!=null) {
canvas=canvascontroler.OpenCanvas();
canvas.drawBitmap(lastFragment.lastFragment, lastFragment.left, lastFragment.top, null);
canvascontroler.CloseCanvas();
lastFragment=null;
}
Bitmap kangoo = BitmapFactory.decodeResource(getResources(),imageId);
// lastFragment=canvascontroler.GetLastFragment(kangoo,(int)x,(int)y);
canvas=canvascontroler.OpenCanvas();
if(canvas!=null){
canvas.drawBitmap(kangoo, x, y, null);
canvascontroler.CloseCanvas();
}
}
mam vyse uvedeny kod a pokud zvyse uvedene tridy zavolam draw image pak se nakresli obrazek do souradnic ktere jsou predavany z venku potud OK
dale mam zaremovanou metodu "// lastFragment=canvascontroler.GetLastFragment(kangoo,(int)x,(int)y);"
jeji kod
public LastCanvasFragment GetLastFragment(Bitmap bm, int left, int top) {
Canvas c = _surfaceHolder.lockCanvas(new Rect(left, top, left + bm.getWidth(), top + bm.getHeight()));
if (c != null) {
LastCanvasFragment ldf = new LastCanvasFragment();
ldf.left = left;
ldf.top = top;
ldf.right = left + bm.getWidth();
ldf.bottom = top + bm.getHeight();
ldf.lastFragment = Bitmap.createBitmap(bm);
try {
c.setBitmap(ldf.lastFragment);
}
catch(IllegalStateException ex) {
//Log.e("Chyba",ex.getMessage());
// Log.println(0,"Chyba",ex.getLocalizedMessage());
ldf=null;
}
_surfaceHolder.unlockCanvasAndPost(c);
return ldf;
}
return null;
ze keter bych si chtel vratit instanci "LastCanvasFragment"
tato trida je definovana nasledne
public class LastCanvasFragment {
public Bitmap lastFragment =null;
public float left;
public float top;
public float right;
public float bottom;
public LastCanvasFragment(){}
}
a jeji clen "public Bitmap lastFragment" by mel vratit prave v tuto chvili pocmaranost canvasu ale pouze z definovanych souradnic
a toto se mi proste vubec nevede
nevite nekdo proc?
dik za kazdou radu