This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
注意你的零。您的评论说 1000,
getMessage
使用 10000,hideMessage
使用 100000(重新发布为答案,因为显然这就是错误的全部)
Pay attention to your zeroes. Your comment says 1000,
getMessage
uses 10000, andhideMessage
uses 100000(reposted as answer since apparently that's all that was wrong)
您不能简单地从任意字节创建字符串 - 字节必须是您正在使用的编码中的字符的编码(在您的情况下,是默认编码)。如果您使用不映射到字符的字节,它们将被映射到
'?'
。另一个方向也是如此:如果字符串中的字符未映射到字节,则getBytes()
方法会将它们映射到(byte)'?'.我认为其中之一或两者都发生在这里。
如果您使用 JPG 或类似的有损图像格式,它会在保存过程中更改图像的字节。
You can't simply create a string from arbitrary bytes - the bytes must be encodings of characters in the encoding you are using (in your case, the default encoding). If you use bytes that don't map to a character, they will be mapped to
'?'
. The same is true in the other direction: If you have a string with characters which do not map to bytes, thegetBytes()
method will map them to(byte)'?'
. I think one or both of this happened here.If you are using JPG or a similar lossy image format, it will change the bytes of your image during saving.
如果计划实际更改部分位图字节,则需要将图像导出为 png,因为它是无损的。 Jpeg 可能会稍微改变字节,这对于图像来说不是问题,但对于文本来说显然很重要。
其次,如果您要选择 100,000 作为插入消息的固定位置,则应该将其设置为常量,以使其更容易且不易出错。说到这里,您当前的固定偏移量偏离了“0”、10,000 和 100,000。
If the plan is to actually change part of your bitmap bytes, you'd need to export the image as png, as its lossless. Jpeg would probably change the bytes slightly, which isn't a problem for an image, but for text its obviously critical.
Second, if you're going to pick 100,000 as a fixed position to insert the message, you should set that up as a constant to make it easier, and less error prone. Speaking of which, your current fixed offsets are off by a '0', 10,000 and 100,000.
但是您应该编辑原始文件,而是
BufferedImage
的实例,然后使用ImageIO
将其重写回文件。But you should edit the raw file, but an instance of
BufferedImage
, then rewrite it back to a file withImageIO
.