Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use anchor to realize clip window in J2ME

Shulou Source: shulou.com Published: 2022-06-02 09:25:07 10月01日 Update

This article mainly shows you the "J2ME clip window can use anchor how to achieve", the content is easy to understand, clear, hope to help you solve your doubts, the following let Xiaobian lead you to study and learn "J2ME clip window can use anchor how to achieve" this article.

/ * drawClip draw part of a picture. The clip window can use anchor. * * @ param g * Graphics * @ param x * int position x * @ param y * int position to be drawn y * @ param image * Image picture * @ param clipX * int clip coordinates in the picture x * @ param clipY * int clip coordinates in the picture y * @ param clipWidth * width of int clip in picture * @ param clipHeight * height of int clip in picture * @ param anchor * int link anchor * / public static void drawClip (Graphics g Int x, int y, Image image, int clipX, int clipY, int clipWidth, int clipHeight, int anchor) {int [] old = {g.getClipX (), g.getClipY (), g.getClipWidth (), g.getClipHeight ()} / / Store the original initial Clip size and coordinates int offsetX = 0, offsetY = 0 Switch (anchor) {/ / the processing of various anchor is the relative offset of Graphics.TOP | Graphics.LEFT / / take the relative offset of Graphics.LEFT relative to Graphics.TOP | Graphics.LEFT, and finally / / draw the figure case Graphics.HCENTER with Graphics.TOP | Graphics.LEFT anchor | Graphics.TOP: offsetX = clipWidth / 2; break Case Graphics.RIGHT | Graphics.TOP: offsetX= clipWidth; break; case Graphics.LEFT | Graphics.VCENTER: offsetY = clipHeight / 2; break; case Graphics.HCENTER | Graphics.VCENTER: offsetX= clipWidth / 2; offsetY = clipHeight / 2; break; case Graphics.RIGHT | Graphics.VCENTER: offsetX= clipWidth; offsetY = clipHeight / 2 Break; case Graphics.LEFT | Graphics.BOTTOM: offsetY = clipHeight; break; case Graphics.HCENTER | Graphics.BOTTOM: offsetX = clipWidth / 2; offsetY = clipHeight; break; case Graphics.RIGHT | Graphics.BOTTOM: offsetX = clipWidth; offsetY = clipHeight; break } g.setClip (x-offsetX, y-offsetY, clipWidth, clipHeight); g.drawImage (image, x-clipX-offsetX, y-clipY-offsetY, Graphics.TOP | Graphics.LEFT); g.setClip (old [0], old [1], old [2], old [3]) / / restore CLIP size position after painting} the above is all the contents of the article "how can clip windows in J2ME be implemented using anchor?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Picture location content coordinates article size offset learning help graphics width that is situation easy to understand more organization knowledge editing industry information Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Shulou Tech Info Apple Microsoft Shulou Technology