简体   繁体   中英

Lines of colored pixel

In a component I must display several lines of colored pixels. Each pixel of the line is given a color. What kind of component is suitable to build the line or what kind of component is suitable to hold pixels?

Just extend JComponent and paint the lines/pixels in the paintComponent() method.

To me the best (but maybe not easiest) way would be implementing a custom Paint class that allows for setting colour regions - a bit like the GradientPaint classes but more flexible.

Then you would call Graphics2D.setPaint(myPaint) just before you draw the line.

The Paint implementation could offer a method setColorForRegion(double start, double end, Color color) with start and end taking values between 0.0 and 1.0 to mark a region on the line.

Might be a bit complicated to implement the Paint class, but the benefit is, that you can resize the lines and draw them in any direction while preserving the color pattern.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM