开发者

Drawing Layers over ImageView in Android

Can anyone guide me how can I put different drawing layers on an Image which is shown over ImageView component. Basically I want to implement Undo and Redo Functionality in my drawing application.

Currently I can put text or Drawing over image but can't achieve Undo/Redo functionality. I wonder this can be possible by maintaining some layering stuff.

Plz help me out.

this is my current drawing code..

    try {

        image.buildDrawingCache();
        Bitmap bitmap = image.getDrawingCache();

        try

        {

            bitmap = getResizedBitmap(bitmap, image.getHeight(),
                    image.getWidth());

        } catch (OutOfMemoryError e) {
            Toast.makeText(getApplicationContext(), e.getMessage(), 1)
                    .show();
        }

        TextPaint tp = new TextPaint();
        tp.setColor(Color.GREEN);
        tp.setAntiAlias(true);
        tp.setTextSize(30);

        Canvas canvas = new Canvas(bitmap);
        canvas.drawText(input.getText().toString(), xPos, yPos, tp);
        image.setImageBitmap(bitmap);

        input.setText("");
        in开发者_开发问答put.setVisibility(View.INVISIBLE);

    } catch (Exception e) {

        Toast.makeText(getApplicationContext(), e.getMessage(), 1).show();
    }

thanks in advance...!!!


Done it in another way. Create orignal bitmap and save it in some bitmap variable. Now on every onDraw call initiate a bitmap with orignal one and pass it to canvas. Then do what you want to do..


Try LayerDrawable from Android

http://developer.android.com/guide/topics/resources/drawable-resource.html#LayerList

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜