我有 JPEG 格式的 RGB 图像。我想将此图像转换为像素并显示在文本文件中。这个怎么做?
public static int[][][] getPixelData(Image image) {
// get Image pixels in 1D int array
int width = image.getWidth(null);
int height = image.getHeight(null);
int[] imgDataOneD = imageToPixels(image);
private static int[] imageToPixels(Image image) {
int height = image.getHeight(null);
int width = image.getWidth(null);
int pixels[] = new int[width * height];
PixelGrabber grabber = new PixelGrabber(image, 0, 0, width, height, pixels, 0, width);
try {
grabber.grabPixels();
} catch (InterruptedException e) {
}
return pixels;
}
如何将此信息以序列向量格式存储在文本文件中?