Results 1 to 2 of 2
Thread: Best Way To Render
- 03-23-2011, 03:55 PM #1Member
- Join Date
- Mar 2009
- Rep Power
Best Way To Render
I am writing a Logic Analyzer host side software (for the logic), and rendering is taking too much resources. This is what the render looks like:
(just the View Window): http://i.imgur.com/Zt70k.png
I have tried:
1) Rendering everything everytime - slow and memory intensive
2) Layers with an alpha, and having 5 layers. 2 are always rendered, and the other 3 are rendered only if it changes, for example, the data layer only if zoom/pan changes. Also slow
The second is my current one. When I profile it, the top 2 major users of time are methods not in my program. One of them is fillRect (which I use, but it is pointing to something else, in a Java SE class). I use this prior to every rendering to fill with transparency, so as to avoid "ghosting". This was changed from making a new BufferedImage everytime, which was even slower.
The other major usage is something I am not familiar with, but was some sort of compositing. I am thinking that this is drawing the transparent BufferedImages to a common BufferedImage.
Together, these 2 account for almost 100% of the rendering time. What can I do to speed it up? Here is the code. It is very messy, as I am slowly converting it, and has some extraneous code. The render method is what is called everytime.
Complete Render Code: [Java] /* * To change this template, choose Tools | Templates * and open the templa - Pastebin.com
Just the relevant bits: // // NOT COMPILABLE // public BufferedImage render(int w, int h, int xP, i - Pastebin.com
I researched it a bit, I found some websites claiming that the Graphics API is one of the hardest to work with because it is so poorly documented in terms of behavior. The example I found was that it uses hardware acceleration, but as soon as you use the setRGB method, it stops.
- 03-24-2011, 07:20 PM #2
Step -1: Render everything that is static to a BufferedImage, this is your background refresh image. (updated rarely)
[Note: do all drawing to one master buffered image: lets call it buffer]
Step 1: Draw background to buffer
Step 2: Draw highlighted rectangle to buffer
Step 3: Draw time tags to buffer
Step 4: Draw lines for each channel to buffer
Step 5: Draw buffer to screen (graphics object)
Repeat 1-5 in a loop (make sure to put in a timer or Thread.sleep(...) as to not use all CPU)
This will be fast.
Another option is to encapsulate each of the channels in a panel, and do similar as above.
Also. For performance use createCompatibleImage:
Graphics2D g2d = (Graphics2D)g; ... BufferedImage buffer = (g2d).getDeviceConfiguration().createCompatibleImage( dim.width, dim.height,java.awt.Transparency.OPAQUE);
Last edited by mrmatt1111; 03-24-2011 at 07:27 PM.My Hobby Project: LegacyClone
- By sherazam in forum Java SoftwareReplies: 0Last Post: 01-31-2011, 10:08 AM
- By sherazam in forum Java SoftwareReplies: 0Last Post: 10-21-2010, 12:09 PM
- By Y. Progammer in forum New To JavaReplies: 6Last Post: 03-12-2010, 03:18 PM
- By toecutter in forum AWT / SwingReplies: 3Last Post: 10-22-2009, 02:43 PM
- By levent in forum Java SoftwareReplies: 0Last Post: 07-26-2007, 09:31 PM