- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在使用 ZXing 代码创建 QR 条形码。我从这里得到了示例代码:http://www.vineetmanohar.com/2010/09/java-barcode-api/并且 PNG 图像看起来不错,如预期的那样是黑白的。
在示例代码注释中提到我可以使用 tiff 或 jpeg 格式,因此我将 imgeFormat 变量更改为 jpeg。创建了一个看起来正确的二维码图像,但不是黑白的,“白色”部分是桃色,“黑色”部分是蓝色。
我将 ZXing MatrixToImageWriter 代码剪切并粘贴到我的代码中并设置颜色,而不是使用 int BLACK = 0xFF000000;和 int WHITE = 0xFFFFFFFF;我发现通过用 0x00000000 替换 BLACK 变量,我的图像变黑了,但我一直无法找到给我白色的 WHITE 变量的值。
附件是奇怪的彩色 QR 条形码。
糟糕,我是新用户,无法附加图像。希望这个指向 imgur.com 的链接有效:http://imgur.com/QnNXO
Java代码如下:
package zxing_qr;
import java.io.File;
import java.io.FileOutputStream;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.WriterException;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;
// by passing MatrixToImageWriter call
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.awt.Graphics2D;
public class Main {
public static void main(String[] args) {
//String text = "98376373783"; // this is the text that we want to encode
String text = "blahblahblah"; // this is the text that we want to encode
int width = 400;
int height = 300; // change the height and width as per your requirement
// (ImageIO.getWriterFormatNames() returns a list of supported formats)
String imageFormat = "jpg"; // could be "gif", "tiff", "jpeg"
try {
BitMatrix bitMatrix = new QRCodeWriter().encode(text, BarcodeFormat.QR_CODE, width, height);
MatrixToImageWriter.writeToStream(bitMatrix, imageFormat, new FileOutputStream(new File("qrcode_97802017507991.jpg")));
} catch (WriterException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} // end main function
} // end main class
最佳答案
我偶然发现了答案。在 ZXing 类 MatrixToImageWriter 中,使用 BufferedImage.TYPE_INT_ARGB 作为第三个参数创建了一个 BufferedImage 对象。通过将其更改为 BufferedImage.TYPE_INT_RGB,jpeg 的颜色将按预期变为黑色和白色。
关于java - 为什么我的 ZXing 的 jpeg 二维码不是黑白的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5943543/
在 Google 和许多 DICOM 章节中可以轻松找到有关 JPEG-LS 的信息。 但是,也有提到 JPEG-LL 的链接/页面/阅读资料。但是,我更深入地研究了 DICOM 标准,没有一章提到过
我有一个关于 DICOM 标准和 libjpeg 库的问题。在 DICOM 标准中,除其他外,还有传输语法: JPEG Lossless, Nonhierarchical, First- Order
APP0 到 APP15 标记每个只支持 65535 字节(我从 libjpeg.doc 中读到的)。如果要在 jpeg 文件中保存更大的数据 block 怎么办? 最佳答案 没有限制使用多个相同类型
我正在尝试构建一个上传器,它分两步上传渐进式文件: 上传最小字节数以创建缩略图 (0-10%) 上传缩略图的其余字节。 (11%-100%) 我想这样做是为了让缩略图更早可用,而不必上传单独的缩略图。
所以,假设我有一个大版本的图像,它只显示为缩略图。是否可以通过使用渐进式 jpeg 来避免为缩略图创建单独的文件,在达到一定数量的扫描时停止加载,并且仅在用户选择完全打开它时继续加载? 如果是这样,如
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 去年关闭。 Improve this
很难说出这里问的是什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或言辞激烈,无法以目前的形式合理回答。如需帮助澄清此问题以便可以重新打开,visit the help center . 9年前关闭
我想从 jpeg 中提取缩略图,无需任何外部库。我的意思是这并不太困难,因为我需要知道缩略图在文件中的开始位置和结束位置,然后简单地剪切它。我研究了许多文档(即: http://www.media.m
当 decoding entropy encoded DC values in JPEG (或 entropy encoded prediction differences in lossless J
问题是:如何区分两个文件?一个用 JPEG 编码,另一个用 JPEG2000 编码。 我需要特定于格式的文件读/写函数,我无法在不读取的情况下找到文件编码。JPEG 现在工作正常,但 JPEG fun
是否有结束 exif/end-of-xmp/end-of-iptc/start-of-data 标记,我可以用它来获取 jpg/jpeg(和其他图像格式)的数据部分的校验和? 最佳答案 我认为这个问题
不久前我收到一封电子邮件,其中包含图像附件。从那时起,hotmail 似乎已停止为我托管图像,因为当我打开邮件时,图像不再可用。 但是,消息源仍然完好无损,如果我没记错的话,消息源 - 以文本形式 -
我有一个提供高质量 MJPEG 的网络摄像头。 我需要通过网络发送小的、低质量的 JPEG。我的硬件是树莓派(700MHz ARM)。我希望代码使用尽可能少的 CPU 能力,并尽可能少地增加延迟。我可
有一个question with the same title但不幸的是它对我没有帮助。 我正在尝试解析 SOS 标记的数据。我能找到的所有文档都说在标记( 0xFFDA )之后是一个两字节的数字,它
每个人! 我处理来自 IP 摄像机的视频,并编写了基于解压缩视频分析的运动检测算法。但我真的更快。我找到了几篇关于压缩域分析的论文,但没有找到任何实现。 谁能推荐我一些代码? 找到的 Material
我在一个网站上工作,该网站涉及显示来自各种在线零售商的大量产品图片。由于大部分页面权重都在图像中,因此我认为值得研究一下减少文件大小的技术。 图像已经是 JPEG。我知道 PNG 有很多多余的东西,可
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a software
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 6 年前。 Improve this ques
我有一个网络画廊,我在其中显示用户上传的文件大小和分辨率各不相同的图像。目前所有图像都是基线。所以我想知道如果我将它们转换为逐行图像是否真的会产生重大影响。使用渐进式图像的优点和缺点是什么。 最佳答案
我在许多链接和网站上保持头脑,但未能得到答案。我不想问这个,我知道 JPEG 压缩,它只制作压缩图像。甚至 Motion JPEG 也会制作压缩图像 I 帧。我的问题是有什么区别。我正在为需要发送视频
我是一名优秀的程序员,十分优秀!