Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Swing / AWT / SWT
Search Coderanch
Advance search
Google search
Register / Login
Forums
Register
Login
Java
»
Swing / AWT / SWT
How to create png image with the pixels array?
xie yufei
,
Greenhorn
Apr 23, 2006 20:44:00
(0 cow)
(0 skulls)
+Pie
Number of slices to send:
Send
I attempt to use MemoryImageSource but I don't know how to create the image and how to reserve the image?
import java.awt.*; import java.awt.image.*; import java.awt.event.*; import java.io.*; import javax.imageio.*; public class Test { public static void main(String[] args) { Color[]colors = { Color.red, Color.yellow, Color.blue, Color.cyan, Color.white, Color.green, Color.magenta, Color.orange}; byte[] reds = { (byte)colors[0].getRed(),(byte)colors[1].getRed(), (byte)colors[2].getRed(),(byte)colors[3].getRed(), (byte)colors[4].getRed(),(byte)colors[5].getRed(), (byte)colors[6].getRed(),(byte)colors[7].getRed() }; byte[] greens = { (byte)colors[0].getGreen(),(byte)colors[1].getGreen(), (byte)colors[2].getGreen(),(byte)colors[3].getGreen(), (byte)colors[4].getGreen(),(byte)colors[5].getGreen(), (byte)colors[6].getGreen(),(byte)colors[7].getGreen() }; byte[] blues = { (byte)colors[0].getBlue(),(byte)colors[1].getBlue(), (byte)colors[2].getBlue(),(byte)colors[3].getBlue(), (byte)colors[4].getBlue(),(byte)colors[5].getBlue(), (byte)colors[6].getBlue(),(byte)colors[7].getBlue()}; IndexColorModel icm = new IndexColorModel( 8, // bits per pixel 8, // size of arrays that follow reds, // red components greens, // green components blues);// blue components Image image; int[] imageBits = new int[] { 0,0,0,1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7, 0,0,0,1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7, 0,0,0,1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7, 0,0,0,1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7, 0,0,0,1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7, 0,0,0,1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7, 0,0,0,1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7, 0,0,0,1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7, 0,0,0,1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7, 0,0,0,1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7}; MemoryImageSource mis = new MemoryImageSource( 24,10, // width, height of image icm,// ColorModel imageBits, // bits of image 0, // offset 24);// scansize image = createImage(mis);//How to create the image ???????????? try { FileOutputStream fos = new FileOutputStream("E:\\chart3.png"); ImageIO.write(image, "png", fos);// How to reserve the image??????? fos.close(); } catch(Exception e) { System.out.println(e); } } }
Ulf Dittmer
,
Rancher
Apr 23, 2006 22:20:00
(0 cow)
(0 skulls)
+Pie
Number of slices to send:
Send
Moved to the AWT/Swing/GUI forum.
Post by:
autobot
I have a knack for fixing things like this ... um ... sorry ... here is a consilitory tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
reply
This thread has been viewed 1908 times.
Similar Threads
To get the color or pixels when the cursor move
Suggestions on colour convertor program
Creating an IndexColorModel with 8 Colours
Image processing
Pixel Transparency
More...
All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 05:59:06
.