In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article is about how to use caching to store screen content as Image in J2ME. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
How to store the contents of the mobile phone screen as an Image object? here we think that what is displayed on the mobile phone screen is a Canvas. The idea to accomplish this function is to use the caching mechanism. We can't get pixels on the Canvas directly, so we can't get the Image object directly from the content on the Canvas. To change the way of thinking, if the content on the Canvas to be drawn is first drawn to an Image, and the Image is not displayed on the screen, it is only displayed on the screen at once after the painting is completed. Experienced friends must have associated with the dual cache mechanism, but this is not to use double cache to solve the problem of the splash screen, but to get the content of the current Canvas.
Let's test this idea by writing a simple Canvas class. SimpleCanvas is a subclass of Canvas. To save the contents of Canvas, we create an Image that is the same size as Canvas.
The following is a reference clip:
Class SimpleCanvas extends Canvas {
Int w
Int h
Private Image offImage = null
Private boolean buffered = true
Public SimpleCanvas (boolean _ buffered) {
Buffered = _ buffered
W = getWidth ()
H = getHeight ()
If (buffered)
OffImage = Image.createImage (w.m. H)
}
Protected void paint (Graphics g) {
Int color = g.getColor ()
G.setColor (0xFFFFFF)
G.fillRect (0pd0rew.h)
G.setColor (color)
Graphics save = g
If (offImage! = null)
G = offImage.getGraphics ()
/ / draw the offimage
G.setColor (128Pol. 128pm 0)
G.fillRoundRect ((wmur100) / 2, (hmur60) / 2Percience 100pr 60pr 5pr 3)
/ / draw the offimage to the canvas
Save.drawImage (offImage,0,0,Graphics.TOP | Graphics.LEFT)
}
Public Image printMe () {
Return offImage
}
You can see that the paint () method does not operate directly on Canvas, but first draws the content to an Image, and then draws it to Canvas. This allows you to call the printMe () method when you want to grab the contents of the screen and return offImage through J2ME's cache. Write a MIDlet to test this effect.
The following is a reference clip:
Package com.J2MEdev
Import Javax.microedition.midlet.*
Import javax.microedition.lcdui.*
/ * *
*
* @ author mingjava
* @ version
, /
Public class PrintScreen extends MIDlet implements CommandListener {
Private Display display = null
Private SimpleCanvas canvas = new SimpleCanvas (true)
Private Command printCommand = new Command ("Print", Command.OK,1)
Public void startApp () {
If (display = = null)
Display = Display.getDisplay (this)
Canvas.addCommand (printCommand)
Canvas.setCommandListener (this)
Display.setCurrent (canvas)
}
Public void pauseApp () {}
Public void destroyApp (boolean unconditional) {}
Public void commandAction (Command command, Displayable displayable) {
If (command = = printCommand) {
Form form = new Form ("screen")
Form.append (canvas.printMe ())
Display.setCurrent (form)
}
}
}
Thank you for reading! This is the end of this article on "how to use cache to store screen content as Image in J2ME". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.