I'm having a bit of trouble using Java's MemoryImageSource methods at the
moment. I was therefore wondering if any of you could help me out!
I've been trying to create an image from an integer array, but with no luck.
I then copied and pasted code from the Java API to see how it worked, but
even that didn't work. (Code below). I keep getting the error-message: can't
resolve symobl 'createImage()'. But I've imported java.awt.image.* which
should be all I need.
Does anyone know what I'm doing wrong? (Must be something very obvious, but
I just can't see it)
I was also wondering if you knew how to read in a ppm image in Java, and if
it was possible to convert it to a gif or jpeg.
I'll be glad for any suggestions you may have!
////////////////////////////////////////////////////////
Code
////////////////////////////////////////////////////////
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.awt.image.MemoryImageSource;
import java.io.*;
import javax.swing.*;
import javax.swing.event.*;
public class ImgSourceTest
{
public static void main (String[] args)
{
Image image;
MemoryImageSource source;
int w = 100;
int h = 100;
int pix[] = new int[w * h];
int index = 0;
for (int y = 0; y < h; y++) {
int red = (y * 255) / (h - 1);
for (int x = 0; x < w; x++) {
int blue = (x * 255) / (w - 1);
pix[index++] = (255 << 24) | (red << 16) | blue;
}
}
source = new MemoryImageSource(w, h, pix, 0, w);
image = createImage(source);
}
}