简体   繁体   English

使用Java按行或按像素读写imag文件

[英]Read/write imag files by lines or by pixels using Java

I have a specific object with image data. 我有一个带有图像数据的特定对象。 And I want read/write images (in BMP, JPEG and PNG formats) to this object. 我想对该对象读取/写入图像(BMP,JPEG和PNG格式)。

Of course, I can read/write image into/from BufferedImage and then copy/paste pixels into/from my object. 当然,我可以在BufferedImage读取/写入图像,然后将像素复制/粘贴到对象中。 But, I want to do it more faster without intermediate objects! 但是,我想要没有中间对象的情况下更快地执行此操作!

How can I perform it over standard Java library or throw other Java library? 如何在标准Java库上执行它或抛出其他Java库?

PS: PS:
I know pngj library that allow read PNG images by lines. 我知道pngj库,允许按行读取PNG图像。 Maybe you know same libraries for BMP, JPEG (or for all of them: BMP, JPEG, PNG)? 也许您知道BMP,JPEG(或所有这些库:BMP,JPEG,PNG)的相同库?

If you want to do all the reading by yourself, you can just open the file with a stream and read it into an array, but you would need to work your way through the whole structure of the file (headers etc...) if you are working with compressed formats you'd have to work on that too. 如果您想自己进行所有读取,则可以仅使用流打开文件并将其读取到数组中,但是如果需要,则需要遍历文件的整个结构(标题等)。您正在使用压缩格式,那么您也必须进行压缩。

Best would be to use imageio to load/write your files and I don't believe there is a lot of overhead coming from the read/write of your images. 最好是使用imageio加载/写入文件,我不认为读取/写入图像会带来很多开销。 Also if you expect to do some heavy work on the images, know that BufferedImages can be hardware accelerated which will improve performance a lot. 另外,如果您希望对图像做一些繁重的工作,请知道BufferedImages可以通过硬件加速,这将大大提高性能。

Why don't you just have the BufferedImage in your Object ? 为什么不只在Object包含BufferedImage BufferedImage isn't all that bad. BufferedImage并不那么糟糕。 Otherwise, you will need to use something like BufferedImage to convert the image file into pixels, and then read the BufferedImage into something like an int[] array of pixels, but it still requires BufferedImage in the middle, and this would slow things down by adding an extra loop to read over and store the pixels. 否则,您将需要使用诸如BufferedImage东西将图像文件转换为像素,然后将BufferedImage读为诸如int[]像素数组之类的东西,但是它仍然需要中间的BufferedImage ,这会使速度变慢添加一个额外的循环以读取并存储像素。

Is there a reason why BufferedImage isn't suitable for your purpose? 为什么BufferedImage不适合您的目的?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM