我正在编写Hadoop/HBase作业.我需要将Java String转换为字节数组.Java String.getBytes()和Hadoop 之间有什么区别Bytes.toBytes()吗?
这不是一个重复的问题,因为我一直在Google和StackOverflow中搜索解决方案,但仍然无法找到解决方案.
我有这两个图像:


这些是来自同一网站的两个图像,具有相同的前缀和相同的格式.唯一的区别是尺寸:第一个更大,而第二个更小.
我将这两个图像下载到本地文件夹,并使用Java将它们读入BufferedImage对象.但是,当我将BufferedImages输出到本地文件时,我发现第一张图像几乎是红色,而第二张图像是正常的(与原始图像相同).我的代码出了什么问题?
byte[] rawData = getRawBytesFromFile(imageFilePath); // some code to read raw bytes from image file
ImageInputStream iis = ImageIO.createImageInputStream(new ByteArrayInputStream(rawData));
BufferedImage img = ImageIO.read(iis);
FileOutputStream fos = new FileOutputStream(outputImagePath, false);
ImageIO.write(img, "JPEG", fos);
fos.flush();
fos.close();
Run Code Online (Sandbox Code Playgroud)
PS:我使用GIMP打开第一张图像并检测到颜色模式是'sRGB',没有alpha或其他东西.