如何在画布上绘制大图像并根据关键事件移动
我有一个大图像。该图像有一些供用户使用的文本。所以我不能调整图像大小以适应较小的屏幕。图像比设备屏幕尺寸大得多。我的目的是在画布上绘制完整的图像而不考虑尺寸。我想根据用户按键事件(左、右、上、下)一点一点地移动图像,比如滚动。
我可以通过以下方式在画布中绘制图像:-
g.drawImage(image, 0, 0, Graphics.TOP | Graphics.LEFT);
我不知道如何根据关键事件进行操作以带来图像的其他部分(例如滚动)。
我见过很多j2me游戏都有这样的功能。
在哪里可以找到这些信息?
I have a large image. This image has some text for user. So I must not resize the image to fit in the smaller screen. Image is much larger than device screen size. My intention is to draw the complete image in canvas without comprising size. I want to move image bit by bit upon user key event (left, right, up, down), something like scrolling.
I can draw an image in canvas by:-
g.drawImage(image, 0, 0, Graphics.TOP | Graphics.LEFT);
I don't know how to act according to key event to bring other parts of the images like scrolling.
I have seen many j2me games having such feature.
Where to look for this information?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 Pngcrush 它的主要目的是通过尝试各种压缩级别来减小 PNG IDAT 数据流的大小如果宽度或长度尺寸很大并且您打算将其绘制在画布上,创建图像后,您可以在画布的paint方法中使用Graphics的drawRegion方法来绘制所需的一块上面的图像。您可以更改通过更改drawRegion()方法的参数并重新绘制画布来绘制一块图像(例如当用户按下一个键时):
这里,第一次从画布中的坐标(ix,iy)绘制图片。
You can use Pngcrush Its main purpose is to reduce the size of the PNG IDAT datastream by trying various compression levels and PNG filter methods.If size of width or length is very large and you intend draw it on canvas,after creating image,you can use drawRegion method of Graphics in paint method of canvas to draw desired piece of image on it.You can change drawed piece of image(for example when user press a key)by change parameters of drawRegion() method and repaint canvas:
Here,first time picture drawn from Coordinate(ix,iy) in canvas.