Hi Chris, I just use RAW format for my screenshot routine - it's crude but it works:
Code:
public static void saveScreenDump(Image screenDump) {
FileConnection conn = null;
DataOutputStream dos = null;
try {
int[] screenDumpRGB = new int[screenDump.getWidth() * screenDump.getHeight()];
screenDump.getRGB(screenDumpRGB, 0, screenDump.getWidth(), 0, 0, screenDump.getWidth(), screenDump.getHeight());
String filename = "" + System.currentTimeMillis() + ".raw";
String fileconn_dir = System.getProperty("fileconn.dir.photos");
if (fileconn_dir == null || "".equals(fileconn_dir))
fileconn_dir = "file:///c:/other/"; // Works K600i and P990i (extremely slow!)
conn = (FileConnection) Connector.open(fileconn_dir + filename, Connector.READ_WRITE);
if (!conn.exists())
conn.create();
dos = conn.openDataOutputStream();
for(int i = 0; i < screenDumpRGB.length; i++)
dos.writeInt(screenDumpRGB[i]);
System.out.println("image saved");
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (dos != null)
dos.close();
if (conn != null)
conn.close();
} catch (IOException e) {
// Well ...
}
}
}
I just did a quick search for a Java ME implementation of a PNG or JPEG encoder, but couldn't find one. But I remember this encoding has to be done manually - there's no function in JSR-135 MMAPI that encodes an Image for you.
Also this doesn't work on Motorola phones unless you have one of their developer certificates. No access to JSR-75 FileConnection API without a certificate.
Anyway the file is [width * height * 4] bytes.
To convert a RAW image to PNG in Java SE:
Code:
if (rawFile.length() == 240 * 320 * 4) {
int[] imageData = new int[240 * 320];
for (int i = 0; i < imageData.length; i++)
imageData[i] = dis.readInt();
BufferedImage image = new BufferedImage(240, 320, BufferedImage.TYPE_INT_ARGB);
image.setRGB(0, 0, 240, 320, imageData, 0, 240);
ImageIO.write(image, "PNG", new File(rawFile.getAbsolutePath().replace(".raw", ".png")));
}