- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我尝试使用ImageIO
将BufferedImage
写入png文件,但每次我将ICC_Profile
添加到IIOMetadata
生成的 png 图像没有嵌入 ICC_Profile
,并且在生成的 png 文件上运行 ImageMagick
识别会产生错误。
我需要的是添加 ICC_Profile 的工作代码。我承认我对 ImageIO 有点新手。我的想法是,我只需将配置文件添加到标题中,无论用于渲染图像的任何内容都应该找到配置文件并在关联的色彩空间中显示图像(如果支持)。我是否错过了应该对这张图片做的其他事情?
另外 - 我想澄清的是,我只想使用 ImageIO 而不是 JAI 的 ColorConvertOp,因为 JAI 已经有 7 年没有开发了,在我看来,最好的方法是使用标准 JDK 类。这是可能的和/或其他人能够实现它吗?
我的代码:
Iterator i = ImageIO.getImageWritersByFormatName("PNG");
if (i.hasNext()) {
ImageWriter imageWriter = (ImageWriter) i.next();
ImageWriteParam param = imageWriter.getDefaultWriteParam();
ImageTypeSpecifier its = new ImageTypeSpecifier(bi.getColorModel(), bi.getSampleModel());
IIOMetadata iomd = imageWriter.getDefaultImageMetadata(its, param);
String formatName = "javax_imageio_png_1.0";
Node node = iomd.getAsTree(formatName);
//add resolution
IIOMetadataNode phys = new IIOMetadataNode("pHYs");
phys.setAttribute("unitSpecifier", "unknown");
phys.setAttribute("pixelsPerUnitXAxis", "300");
phys.setAttribute("pixelsPerUnitYAxis", "300");
//add ICC PROFILE
IIOMetadataNode iccp = new IIOMetadataNode("iCCP");
//ICC_Profile pro = Util.getAdobeRGBICCProfile();
iccp.setUserObject(parameters.getOriginalICC());
iccp.setAttribute("profileName", "AdobeRGB1998");
iccp.setAttribute("compressionMethod", "deflate");
node.appendChild(phys);
node.appendChild(iccp);
try {
iomd.setFromTree(formatName, node);
} catch (IIOInvalidTreeException e) {
System.out.println("IIOInvalidTreeException Occurred setting resolution on PNG EXIF Header.");
e.printStackTrace(System.out);
}
IIOImage iioimage = new IIOImage(bi, null, iomd);
try {
imageWriter.setOutput(new FileImageOutputStream(new File(fileName)));
imageWriter.write(iioimage);
} catch (IOException e) {
System.out.println("Error Occurred setting resolution on PNG.");
e.printStackTrace(System.out);
}
}
Image Magick 识别输出:
Image: /adobe.png
Format: PNG (Portable Network Graphics)
Class: DirectClass
Geometry: 399x508+0+0
Resolution: 300x300
Print size: 1.33x1.69333
Units: Undefined
Type: TrueColorAlpha
Endianess: Undefined
Colorspace: sRGB
Depth: 8-bit
Channel depth:
red: 8-bit
green: 8-bit
blue: 8-bit
alpha: 1-bit
Channel statistics:
Red:
min: 0 (0)
max: 255 (1)
mean: 34.4178 (0.134972)
standard deviation: 82.6482 (0.324111)
kurtosis: 2.12664
skewness: 2.01838
Green:
min: 0 (0)
max: 252 (0.988235)
mean: 27.8842 (0.10935)
standard deviation: 71.8833 (0.281895)
kurtosis: 4.11874
skewness: 2.41137
Blue:
min: 0 (0)
max: 254 (0.996078)
mean: 28.1182 (0.110267)
standard deviation: 73.4184 (0.287915)
kurtosis: 4.25472
skewness: 2.44667
Alpha:
min: 0 (0)
max: 255 (1)
mean: 38.5321 (0.151106)
standard deviation: 91.3288 (0.358152)
kurtosis: 1.79587
skewness: -1.9483
Image statistics:
Overall:
min: 0 (0)
max: 255 (1)
mean: 76.722 (0.300871)
standard deviation: 80.2016 (0.314516)
kurtosis: 4.15993
skewness: 2.43672
Alpha: none #00000000
Rendering intent: Perceptual
Gamma: 0.454545
Chromaticity:
red primary: (0.64,0.33)
green primary: (0.3,0.6)
blue primary: (0.15,0.06)
white point: (0.3127,0.329)
Background color: white
Border color: srgba(223,223,223,1)
Matte color: grey74
Transparent color: none
Interlace: None
Intensity: Undefined
Compose: Over
Page geometry: 399x508+0+0
Dispose: Undefined
Iterations: 0
Compression: Zip
Orientation: Undefined
Properties:
date:create: 2013-12-30T10:23:05-06:00
date:modify: 2013-12-30T10:23:05-06:00
png:IHDR.bit-depth-orig: 8
png:IHDR.bit_depth: 8
png:IHDR.color-type-orig: 6
png:IHDR.color_type: 6 (RGBA)
png:IHDR.interlace_method: 0 (Not interlaced)
png:IHDR.width,height: 399, 508
png:pHYs: x_res=300, y_res=300, units=0
png:sRGB: intent=0 (Perceptual Intent)
signature: f03e01954623f646c9b594d0b2234ca444bb5c8282e923c8af520e08753fed0d
Artifacts:
filename: /adobe.png
verbose: true
Tainted: False
Filesize: 68.3KB
Number pixels: 203K
Pixels per second: 20.27MB
User time: 0.000u
Elapsed time: 0:01.009
Version: ImageMagick 6.8.6-6 2013-10-12 Q16 http://www.imagemagick.org
identify: iCCP: Data error in compressed datastream `/adobe.png' @ warning/png.c /MagickPNGWarningHandler/1830.
identify: Profile size field missing from iCCP chunk `/adobe.png' @ warning/png.c/MagickPNGWarningHandler/1830.
任何帮助将不胜感激。谢谢。
最佳答案
我问的原因是我不认为您的 ICC 配置文件是 deflate 压缩的 byte[]
。你说“这不是问题”,但我真的认为这是问题。 :-)
如果我不对 ICC 配置文件应用 deflate 压缩,我会从 ExifTool 收到类似的警告,就像从识别中收到的警告一样。
Warning : Error inflating iCCP
ICC Profile : (Binary data 526 bytes, use -b option to extract)
如果我对 ICC 配置文件正确应用 deflate 压缩,ICC 配置文件将被正确识别为“Adobe RGB 1998”。
Profile CMM Type : ADBE
Profile Version : 2.1.0
Profile Class : Display Device Profile
Color Space Data : RGB
[...]
CMM Flags : Not Embedded, Independent
Rendering Intent : Perceptual
Connection Space Illuminant : 0.9642 1 0.82491
Profile Creator : ADBE
Profile ID : 0
Profile Copyright : Copyright 2000 Adobe Systems Incorporated
Profile Description : Adobe RGB (1998)
以下代码对我有用:
public class PNGICCProfileIssue {
public static void main(String[] args) throws IOException {
File input = new File(args[0]);
BufferedImage image = ImageIO.read(input);
Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("PNG");
if (!writers.hasNext()) {
return;
}
ImageWriter writer = writers.next();
writer.setOutput(ImageIO.createImageOutputStream(new File(input.getParent(), input.getName().replace('.', '_') + "_icc.png")));
IIOMetadata imageMetadata = writer.getDefaultImageMetadata(ImageTypeSpecifier.createFromRenderedImage(image), writer.getDefaultWriteParam());
//add ICC PROFILE
IIOMetadataNode iccp = new IIOMetadataNode("iCCP");
ICC_ColorSpace colorSpace = (ICC_ColorSpace) ColorSpaces.getColorSpace(ColorSpaces.CS_ADOBE_RGB_1998);
iccp.setUserObject(getAsDeflatedBytes(colorSpace));
iccp.setAttribute("profileName", "AdobeRGB1998");
iccp.setAttribute("compressionMethod", "deflate");
Node nativeTree = imageMetadata.getAsTree(imageMetadata.getNativeMetadataFormatName());
nativeTree.appendChild(iccp);
imageMetadata.mergeTree(imageMetadata.getNativeMetadataFormatName(), nativeTree);
writer.write(new IIOImage(image, null, imageMetadata));
}
private static byte[] getAsDeflatedBytes(ICC_ColorSpace colorSpace) throws IOException {
byte[] data = colorSpace.getProfile().getData();
ByteArrayOutputStream deflated = new ByteArrayOutputStream();
DeflaterOutputStream deflater = new DeflaterOutputStream(deflated);
deflater.write(data);
deflater.flush();
deflater.close();
return deflated.toByteArray();
}
我认为这个要求应该记录在元数据文档中,因为我必须告诉你,这有点令人困惑。
祝你好运!
关于java - 如何在IIOMetadata中嵌入ICC_Profile(Adobe98)并使用ImageIO写入PNG?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20843873/
我有这个代码 var myChart = new FusionCharts("../themes/clean/charts/hbullet.swf", "myChartId", "400", "75
既然写入是立即进行的(复制到内核缓冲区并返回),那么使用 io_submit 进行写入有什么好处? 事实上,它 (aio/io_submit) 看起来更糟,因为您必须在堆上分配写入缓冲区并且不能使用基
我正在使用 mootool 的 Request.JSON 从 Twitter 检索推文。收到它后,我将写入目标 div 的 .innerHTML 属性。当我在本地将其作为文件进行测试时,即 file:
最终,我想将 Vertica DB 中的数据抓取到 Spark 中,训练机器学习模型,进行预测,并将这些预测存储到另一个 Vertica DB 中。 当前的问题是确定流程最后部分的瓶颈:将 Spark
我使用 WEKA 库编写了一个 Java 程序, 训练分类算法 使用经过训练的算法对未标记的数据集运行预测 将结果写入 .csv 文件 问题在于它当前写出离散分类结果(即算法猜测一行属于哪个类别)。我
背景 - 我正在考虑使用 clickonce 通过 clickonce(通过网站)部署 WinForms 应用程序。相对简单的应用程序的要素是: - 它是一个可执行文件和一个数据库文件(sqlite)
是否有更好的解决方案来快速初始化 C 数组(在堆上创建)?就像我们使用大括号一样 double** matrix_multiply(const double **l_matrix, const dou
我正在读取 JSON 文件,取出值并进行一些更改。 基本上我向数组添加了一些值。之后我想将其写回到文件中。当我将 JSONArray 写回文件时,会被写入字符串而不是 JSONArray 对象。怎样才
我为两个应用程序使用嵌入式数据库,其中一个是服务器,另一个是客户端。客户端应用程序。可以向服务器端发送获取数据请求以检索数据并显示在表格(或其他)中。问题是这样的:如何将获取的数据保存(写入)到页面文
是否有更好的解决方案来快速初始化 C 数组(在堆上创建)?就像我们使用大括号一样 double** matrix_multiply(const double **l_matrix, const dou
从问题得出问题:找到所有 result = new ArrayList(); for (int i = 2; i >(i%8) & 0x1) == 0) { result.add(i
由于某种原因,它没有写入 CSV。谁能明白为什么它不写吗? def main(): list_of_emails = read_email_csv() #read input file, cr
关闭。 这个问题是 not reproducible or was caused by typos 。它目前不接受答案。 这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能在这里出现,
我目前正在开发一个保存和加载程序,但我无法获得正确的结果。 编写程序: #include #include #define FILENAME "Save" #define COUNT 6 type
import java.io.*; public class Main2 { public static void main(String[] args) throws Exception {
我需要使用预定义位置字符串“Office”从所有日历中检索所有 iOS 事件,然后将结果写入 NSLog 和 UITextView。 到目前为止,这是我的代码: #import "ViewCo
我正在尝试将 BOOL 值写入 PFInstallation 中的列,但会不停地崩溃: - (IBAction)pushSwitch:(id)sender { NSUserDefaults *push
我以前在学校学过一些简单的数据库编程,但现在我正在尝试学习最佳实践,因为我正在编写更复杂的应用程序。写入 MySQL 数据库并不难,但我想知道让分布式应用程序写入 Amazon EC2 上的远程数据库
是否可以写回到ResourceBundle?目前我正在使用 ResourceBundle 来存储信息,在运行时使用以下内容读取信息 while(ResourceBundle.getBundle("bu
关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。 这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topi
我是一名优秀的程序员,十分优秀!