Android 中在 ImageView 上绘制图层
谁能指导我如何在 ImageView 组件上显示的图像上放置不同的绘图层。 基本上我想在我的绘图应用程序中实现撤消和重做功能。
目前我可以在图像上放置文本或绘图,但无法实现撤消/重做功能。我想知道这可以通过维护一些分层的东西来实现。
请帮帮我。
这是我当前的绘图代码..
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("");
input.setVisibility(View.INVISIBLE);
} catch (Exception e) {
Toast.makeText(getApplicationContext(), e.getMessage(), 1).show();
}
提前感谢...!!!
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("");
input.setVisibility(View.INVISIBLE);
} catch (Exception e) {
Toast.makeText(getApplicationContext(), e.getMessage(), 1).show();
}
thanks in advance...!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
用另一种方式完成。
创建原始位图并将其保存在某个位图变量中。现在,在每个 onDraw 调用中都会使用原始位图启动一个位图并将其传递到画布。然后做你想做的事..
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..
尝试 Android 中的 LayerDrawable
http://developer.android.com/guide /topics/resources/drawable-resource.html#LayerList
Try LayerDrawable from Android
http://developer.android.com/guide/topics/resources/drawable-resource.html#LayerList