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
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
Liutauras Vilda
Jeanne Boyarsky
paul wheaton
Sheriffs:
Ron McLeod
Devaka Cooray
Henry Wong
Saloon Keepers:
Tim Holloway
Stephan van Hulst
Carey Brown
Tim Moores
Mikalai Zaikin
Bartenders:
Frits Walraven
Forum:
Swing / AWT / SWT
How to create png image with the pixels array?
xie yufei
Greenhorn
Posts: 19
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
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
Posts: 43081
77
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Moved to the AWT/Swing/GUI forum.
Try 100 things. 2 will work out, but you will never know in advance which 2. This tiny ad might be one:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
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...