像素差
我是 Java 编程的初学者。我必须提交服务器-客户端项目,并且我陷入了像素比较。 .acc to code 它接受 BufferedImage 并比较像素。如何存储第二张图像本身的像素差异并返回它?
I'm a beginner in Java programming. I have to submit project of server- client and I am stuck in pixel comparison. .acc to code It accepts BufferedImage
and compares pixels. How to store the pixel difference in the 2nd image itself and return it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看一下
BufferedImage
的 getRGB(int x, int y) 方法。这将以 int 形式提供给定 (x, y) 位置的近似 RGB 值,然后可以将其与其他图像中的相应位置进行比较。如果您希望执行更详细的比较,则需要分别迭代每个图像波段,将该波段的样本与其他图像的相应波段进行比较。 (例如,RGBA 编码图像有四个单独的波段可供比较,而灰度图像只有一个。)
显然,您可以首先比较图像尺寸以确保它们相等,然后再进行更详细的比较。
另外,你不应该指望人们粘贴详细的代码解决方案;这不是 Stack Overflow 的工作方式 - 人们会更愿意帮助解决
特定问题
,因此您应该尝试编写解决方案,并在遇到困难时发布代码片段。Take a look at
BufferedImage
's getRGB(int x, int y) method. This will provide an approximate RGB value for the given (x, y) location as an int, which can then be compared to the corresponding location in the other image.If you wish to perform a more detailed comparison you'll need to iterate over each image band separately, comparing the samples for that band with the corresponding band for the other image. (For example, an RGBA encoded image has four individual bands to compare, whereas a greyscale image has just one.)
Obviously you could start by comparing the image dimensions to ensure they are equal before proceding to the more detailed comparison.
Also, you should not expect people to paste detailed code solutions; That's not the way Stack Overflow works - People will be far more willing to help with
specific problems
so you should try coding the solution and post a code snippet if you get stuck.