jpeg如何在使用java代码上传到Bugzilla工具时获得图像的实际颜色而不失真?
**我正在使用下面的代码将多个故障截图从文件夹中提取到Bugzilla工具,在Bugzilla中上载图片时,图片的颜色被破坏。[在此处输入图像描述][1]。有人能帮我纠正这个问题吗?**
try {
BugzillaConnector conn = new BugzillaConnector();
conn.connectTo("bugzilla.com");
LogIn logIn = new LogIn("username", "password");
conn.executeMethod(logIn);
Bug bug = new BugFactory()
.newBug()
.setProduct("SeleniumFramework")
.setComponent("CoreJavaTestNG")
.setVersion("1.0").setPlatform("PC")
.setOperatingSystem("Windows")
.setDescription("Bug posted from Java Source Code")
.setSummary("Bug posted from Java Source Code")
.createBug();
ReportBug report = new ReportBug(bug);
conn.executeMethod(report);
int bugID = report.getID();
System.out.println("Bug posted and its ID is " + bugID);
GetBug get = new GetBug(bugID);
conn.executeMethod(get);
System.out.println(get.getBug().getID());
System.out.println(get.getBug().getSummary());
System.out.println(get.getBug().getProduct());
System.out.println(get.getBug().getComponent());
System.out.println(get.getBug().getVersion());
System.out.println(get.getBug().getPlatform());
System.out.println(get.getBug().getOperatingSystem());
// Passing txtFileFilter to listFiles() method to retrieve only file start with fail files
File[] files = folder.listFiles(txtFileFilter);
int Count = 0;
for (File file : files) {
BufferedImage bImage = ImageIO.read(new File(FilePath + file.getName()));
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ImageIO.write(bImage, "jpg", bos );
byte [] data = bos.toByteArray();
AttachmentFactory attachmentFactory = new AttachmentFactory();
Attachment attachment = attachmentFactory.newAttachment()
. setData(data)
. setMime("image/jpg") //Set the appropriate MIME type for the image format
. setSummary(file.toString()) //Description
. setName(file.toString())//Name of the Screenshot in Bugzilla
. setBugID(bugID)
. createAttachment();
AddAttachment add2 = new AddAttachment(attachment, bugID);
add2.getID();
conn.executeMethod(add2);
Count++;
}
System.out.println(Count + " File Uploded");
}
catch (Exception e) {
e.printStackTrace();
} ```
[1]: https://i.stack.imgur.com/qrIaq.jpg
# 1 楼答案
你看到的粉红色/浅红色是因为源图像包含一个alpha通道
在
ImageIO
中有一个已知的bug,它会将alpha通道包含到JPEG图像的输出中(或者类似的东西,如果你真的感兴趣,可以用谷歌搜索)问题的基本解决方案是使用
TYPE_INT_RGB
将原始图像应用于BufferedImage
,这将删除alpha通道,例如请参见Removing transparency in PNG BufferedImage所以,从这个透明的PNG开始
使用下面的代码
我可以生产
如果您仍然有问题,那么您需要做两件事:
在评论中持续发布代码是没有帮助的