如何滚动位图?
我有一个图像视图(为其分配了一个位图)和另一个用于绘画的位图(透明)。如何同时滚动此位图和背景位图以在不同的位置绘制。
I have one image view (assigned one bitmap to it) and another bitmap (Transparent) for painting. How it is possible to scroll this bitmap and background bitmap at the same time to be painted at different places.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我了解,您正在尝试在图像上绘图。如果是这种情况,请创建一个自定义视图并使用 BitmapFactory 获取图像。获取位图对象后,使用其复制方法并将该副本用于视图的画布。
现在您可以重写自定义视图的 onDraw 方法并在其上绘制任何内容。
该视图可以添加到布局中,并且该视图将发生滚动。
编辑:示例代码
好的,这是一些可能对您有帮助的代码。我没有时间浏览你所有的代码。
但我试图理解你的要求。
我正在显示活动的代码、其 xml 和自定义视图
Activity.java
draw_demo_layout.xml
DrawView.java
此活动有一个框架布局,其中有一个图像视图作为保存位图的基础。
我们在其顶部添加一个自定义绘图视图,并在其上进行绘图。当我们想要清除绘图时,我们会删除绘图视图,并在需要再次绘图时添加另一个绘图视图。
这可能不是最有效的方法。但应该让你开始。
From what I understood you are trying to draw on top of a image. If thats the case, create a custom view and get the image using BitmapFactory. After you get a bitmap object, use its copy method and use that copy for the canvas of the view.
Now you can override the onDraw method of a custom view and draw anything on top of it.
This view can be added to the layout, and scrolling will happen to the view.
Edit: Sample Code
Ok this is some code that might help you. I dont have the time to go through all your code.
But I tried to understand your requirement.
I am showing the code for an activity, its xml and custom view
Activity.java
draw_demo_layout.xml
DrawView.java
This activity has a framelayout which has a imageview as the base which holds the bitmap.
We add a custom draw view on top of it and do our drawings on it.When we want to clear the drawing we remove the drawview and add another one if we need to draw again.
This might not be the most efficient way. But should get you started.