Context
I'm trying to converting a binary file (this is a raw memory file, dumped from pmemsave
instruction of QEmu monitor) to PNG file with RGB color. That's mean each 3 bytes equal Red-Green-Blue color in 1 pixel of PNG file.
My idea is below:
content in binary file: 10001000 10100010 11000101 # and so on...
convert to RGB color in 1 pixel of PNG file: #88a2c5
In my imagine, the workflow of this program is same as this:
# define the chunk size is 128MB
CHUNK_SIZE = 134217728
# create new png file
png.new("dest.png", format=RGB)
# open file for writing content
png.open_for_read()
while not end of source file:
data = source.read(CHUNK_SIZE)
# another process...
png.append(data)
png.save_on_disk()
Problem
I think it's very easy to do it by using ImageIO
from javax
. But my source file is really big (almost 2.1GB in size), so that the method ImageIO.write
can't handle as well. By default, this method does not support chunking (it will destroy content in dest file if it exist).
How can I solve this problem? It's really happy for me to have any solution with modern feature of Java (like stream
or something else)