Reputation: 13390
This question is related to my previous question but you dont need to read that in order to understand it.
Now I was trying to convert bitmap into smaller parts and then save those smaller parts.
Issue I get is, Only the first part gets saved in the file whose size is way bigger than the full image. Below is the code I am using:
for (int i = 0; i < Image.getHeight(); i++)
{
fout = new FileOutputStream(file, true);
Bitmap temp = Bitmap.createBitmap(Image, 0, i,Image.getWidth(), 1);
temp.compress(Bitmap.CompressFormat.PNG, 100, fout);
fout.flush();
fout.close();
}
The Code is pretty simple but i dont understand that why the only first row gets written in the file.
UPDATE:: Merlin and Deepak are right. I tried now with giving different names and all the parts were successfully written to different files. Now you know the problem, should i go for the removing of header from second chunk and removing of eof from first chunk or what?
Upvotes: 2
Views: 1621
Reputation: 10193
I'm going to resist the urge to ask why on earth you are doing this as it is highly inefficient, so let's have a look.
So you are writing one line of pixels at a time but you are writing them to the same file repeatedly with the append flag set to true which is correct.
What you have missed is the fact that when you write a bitmap you are writing is self contained. So a program reading th first line will expect that to be the entire bitmap.
This is the equivalent of having an EOF marker in a text file. All the lines are being written but when reading it the reader gives up after the first EOF
You would need to research the the structure of a PNG file to understand more fully what is happening
Upvotes: 3
Reputation: 59168
Your logic is wrong because you cannot append each row as png to a file. Probably it has some header stuff, so they would be appended after each append.
Upvotes: 1
Reputation: 1141
Since you are appending compressed files (.png) one after the other, opening the resultant file will just show the first bit encoded data, which is your first row. This is logical too since the encoded image header has number of bytes comprising the encoded content and the decoders will not bother about the rest of the data in the file after end marker.
I just tried copying an .png file at the end of another, when i open the file i seen the unchanged first image!
Upvotes: 1