如何在 android 中实现 OpenGL 中的涂鸦视图?
我有一个安卓应用程序。我想使用 OpenGL 渲染图像并添加效果。我还想要一个单独的视图,用户可以在其中涂鸦。我希望视图的背景颜色是透明的。我还想在放大或缩小图像时放大和缩小。我想我应该使用 glScalef()
来控制放大和缩小。但当我缩放(放大)视图时,我还需要增加笔的宽度。我想在 openGL 中写这个视图。我是 android 和 openGL 的新手。请用你的想法指导我。
I have an android application. I want to use OpenGL to render my images and add effects. also I want a separate view where user can scribble on. I want the background color of the view to be transparent. I also want to zoom in and out as I zoom in or out the image. I am thinking I shall control the zoom in and out using glScalef()
. But I shall also need to increase the pen width as I zoom (scale up) the view. I want to write this view in openGL. I am new to android and openGL. please guide me with your ideas.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我尝试了一种不同的方法来实现在 glSurfaceView 上涂鸦的功能,并同时能够放大和缩小。我已经在普通的 android 提供的画布上完成了所有的涂鸦。在后台我有一个 GLSurfaceView。在它的顶部,我有一个涂鸦视图(http://www.java2s.com/Code/Android/2D-Graphics/Classforthescribblememopad.htm)。我已将 ScribbleView 的背景设置为透明。当我完成涂鸦后,我使用按钮的 onClickListener 关闭涂鸦(当涂鸦关闭时,用户可以放大和缩小)。我可以使用 ScaleGestureDetector.SimpleOnScaleGestureListener 进行放大或缩小。在其 onScale() 中,我使用 mScaleFactor=(mScaleFactor * detector.getScaleFactor()); 其中 mScaleFactor 初始化为 1f,mScaleFactor 用于跟踪当前的 ScalingFactor。对于 glSurface 的缩放,我使用
glScalef(mScaleFactor,mScaleFactor)
,对于画布缩放,我使用canvas.scale(mScaleFactor,mScaleFactor,getWidth()/2,getHeight()/2)
代码>.我已将枢轴点设置为视图的中间,因为画布的坐标使其原点位于左上角。在我放大或缩小画布之后然后为了正确的涂鸦,我在涂鸦视图的 onTouchEvent(Event event) 中进行了以下映射,现在
当我在放大或缩小的画布上涂鸦时,我可以在该点涂鸦我正确触摸屏幕的地方。
我希望我能够让大家对我的方法有所了解。
谢谢克里希纳。
I have tried a different approach to implement my functionality of scribbling over a glSurfaceView and simultaneously be able to zoom in and zoom out. I have done all the scribbling over normal android provided canvas. In the background I have a GLSurfaceView. On top of it i have a scribbble view (http://www.java2s.com/Code/Android/2D-Graphics/Classforthescribblememopad.htm). I have set the background of ScribbleView as TRANSPARENT. When I am done Scribbling I put scribbling off using onClickListener of a Button (when scribbling is off user can zoom in and zoom out). I can zoom in or out using ScaleGestureDetector.SimpleOnScaleGestureListener. In its
onScale()
I am usingmScaleFactor=(mScaleFactor * detector.getScaleFactor());
Where mScaleFactor is initlised to 1f and mScaleFactor is used to track the current ScalingFactor. For scaling of glSurface I useglScalef(mScaleFactor,mScaleFactor)
and for canvas scaling I usecanvas.scale(mScaleFactor,mScaleFactor,getWidth()/2,getHeight()/2)
. I have set the pivot point to middle of the view as the coordinates of the canvas is such that its origin is at top left.After I scale up or scale down the canvas Then for correct scribbling I have in onTouchEvent(Event event) of Scribble view I have done the below mapping for the
Now when I do scribbling on the zoomed in or out canvas I can scribble at the point where I touch the screen correctly.
I hope I have been able to give you all some insight of my approach.
Thanks Krishna.