位图和 BufferedImage 之间的差异
我正在尝试将一些代码从常规 Java 程序移植到 Android 平台中。不幸的是,该程序的一个重要部分涉及操作图像,而 Java 的 AWT 被剥夺了。我试图用 Bitmap
替换 awt.BufferedImage
,并希望这两个类之间的唯一区别是它们的接口。我阅读了一些文档,看起来确实如此,但是在将所有图像内容包装到一个漂亮的小类中并在我的开发机器和实际手机上测试几乎相同的代码之后,一个程序可以运行并且另一个则不然。那么:
颜色的编码不会改变——对吗?它仍然是 0xAARRGGBB
- 对吗?
图像本身没有改变 - 对吗?当我将图像放入 res/drawable
中时,它是完全相同的图像。最值得注意的是,他们不会以任何方式改变分辨率 - 对吧?
访问像素本质上是相同的 - 对吧?我基本上用 get/setPixel(x,y,color)
替换了所有 get/setRGB(x,y,RGB)
。网格索引方法没有变化 - 是吗?
I am trying to port some code from a regular Java program into the Android platform. Unfortunately, a significant part of the program involves manipulating images, and Java's AWT was taken away from me. I am trying to replace awt.BufferedImage
with Bitmap
, and was hoping that the only differences between the two classes would be their interfaces. I read some of the documentation, and it looked like that is true, but after wrapping all of the image stuff into a nice little class and testing almost-the-same code on both my development machine and an actual phone, one program works and the other does not. So:
The encoding for color does not change - right? It is still 0xAARRGGBB
- right?
The images themselves are not changed - right? When I put an image into res/drawable
, it is exactly the same image. Most notably, they don't alter the resolution in any way - right?
Accessing the pixels is essentially the same - right? I essentially replaced all of my get/setRGB(x,y,RGB)
with get/setPixel(x,y,color)
. There are no changes to the method of indexing into the grid - is there?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
已解决:打开图像时,我无法创建将
inDither
设置为 false 的BitmapFactory.Options()
。然后,BitmapFactory
无法生成精确的副本,因此对生成的Bitmap
进行了一些更改,以使其显示起来更美观。Solved: when opening the image, I failed to create a
BitmapFactory.Options()
withinDither
set to false. TheBitmapFactory
then failed to produce an exact copy, putting some alterations in the resultingBitmap
in order to make it more pleasing for display.