(2006年1月7日、試してみたらあっさり出来た。ここもそのうちに整理。)
個人的には剥製みたいな MPEG ファイルよりも、 対話的なシミュレーション・プログラム+台本みたいなのが理想だと 思っているのだけど。
http://www.javadrive.jp/java2d/bufferedImage/index2.html
http://tokunagakenichi.net/java/sample/JPEG/JpegSave.java
import java.awt.image.*;
BufferedImage im = null;
..
// TYPE_INT_BGR というのもある
im = new BufferedImage(幅, 高さ, BufferedImage.TYPE_3BYTE_BGR);
..
Graphics g = im.getGraphics();
g に色々描画
getGraphics().drawImage(im, 0, 0, this); のようにして実際に表示
// 出力するためのメソッド
public void saveJpegFile(OutputStream output) throws IOException {
JPEGImageEncode jpeg = JPEGCodec.createJPEGEncoder(output);
jpeg.encode(image);
output.flush();
output.close();
}
// メソッドの呼び出し
try {
saveJpegFile(new FileOutputStream("test.jpg"));
}
catch (IOException e) {
e.printStackTrace();
}
|
BufferedImage im_w, im_r = null;
boolean result = false;
// im_w に用意してあれば次のようにして出力できる
try {
result = ImageIO.write(im_w, "jpeg", new File("test.jpg"));
}
catch (Exception e) {
e.printStackTrace();
result = false;
}
// 読む方は
try {
im_r = ImageIO.read(new File("my.png"));
}
catch (Exception e) {
e.printStackTrace();
im_r = null;
}
if (im_r == null) {
im_r = new BufferedImage(...
}
Graphics bg = im_r.createGraphics();
...
|