Android : What is the difference between converting Bitmap to byte array and Bitmap.compress? -


i uploading image (jpeg) android phone server. tried these 2 methods -

method 1 :

int bytes=bitmap.getbytecount();         bytebuffer bytebuffer=bytebuffer.allocate(bytes);         bitmap.copypixelstobuffer(bytebuffer);         byte[] bytearray = bytebuffer.array();         outputstream.write(bytearray, 0, bytes-1); 

method 2 :

bitmap.compress(bitmap.compressformat.jpeg,100,outputstream); 



in method1, converting bitmap bytearray , writing stream. in method 2 have called compress function given quality 100 (which means no loss guess).

expected both give same result. results different. in server following happened -
method 1 (the uploaded file in server) :
file of size 3.8mb uploaded server. uploaded file unrecognizable. not open image viewer.

method 2 (the uploaded file in server)
jpeg file of 415kb uploaded server. uploaded file in jpeg format.

difference between 2 methods. how did size differ though gave compression quality 100? why file not recognizable image viewer in method 1?

i expected both give same result.

i have no idea why.

what difference between 2 methods.

the second approach creates jpeg file. first 1 not. first 1 merely makes copy of bytes form decoded image supplied buffer. not in particular file format, let alone jpeg.

how did size differ though gave compression quality 100?

because first approach applies no compression. 100 jpeg quality not mean "not compressed".

also why file not recognizable image viewer in method 1?

because bytes copied buffer not being written in particular file format, , not jpeg. buffer not designed written disk. rather, buffer designed used re-create bitmap later on (e.g., bitmap passed on ipc).


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -