What is the fastest way to draw pixels in Java

前端 未结 5 2048
无人共我
无人共我 2020-12-28 23:52

I have some code that generates particles at random locations, and moving in random directions and speed.

Each iteration through a loop, I move all the particles, an

5条回答
  •  甜味超标
    2020-12-29 00:09

    You should be getting a much faster frame rate on a standard computer when using the img.getRaster().getDataBuffer().getData(). I know this for a fact because I can paint the entire screen in 20-30 frames per second and the screen has 1,000,000 pixels total. I obtained this speed by cutting the rendering routine in two and using two threads. My CPU is 1.5ghz.

    For this reason, I think that you may have made a coding error in moving the pixels. Remember: creating a new object is a 100x times longer operation than addition. Also see if you can cut out any if statements.

    Also, this may be silly, but I assume you are only calling img.getRaster().getDataBuffer().getData() once per frame?

    On a related note, Drawing multi pixel particles will naturally take a long time.

提交回复
热议问题