私の要件はこのようなものです。ファイル接続を使用して携帯電話からファイルを読み取り、その画像のサムネイルを作成してサーバーに投稿する必要があります。FileConnection API を使用して画像を読み取ることができ、サムネイルを作成することもできます。
サムネイルを作成した後、その画像を byte[] に戻す方法が見つかりません。出来ますか?
サムネイル変換のコード:
private Image createThumbnail(Image image) {
int sourceWidth = image.getWidth();
int sourceHeight = image.getHeight();
int thumbWidth = 128;
int thumbHeight = -1;
if (thumbHeight == -1)
thumbHeight = thumbWidth * sourceHeight / sourceWidth;
Image thumb = Image.createImage(thumbWidth, thumbHeight);
thumb.getGraphics();
Graphics g = thumb.getGraphics();
for (int y = 0; y < thumbHeight; y++) {
for (int x = 0; x < thumbWidth; x++) {
g.setClip(x, y, 1, 1);
int dx = x * sourceWidth / thumbWidth;
int dy = y * sourceHeight / thumbHeight;
g.drawImage(image, x - dx, y - dy);
}
}
Image immutableThumb = Image.createImage(thumb);
return thumb;
}