android - Decoded bitmap results in larger size -


I'm trying to store a bitmap (which I've already read from a file) in a better shape After decoding, BitmapFactory.Options.inSampleSize . The problem is that the file size of the stored bitmap is at least double the size of the original file. I have searched a lot and how can I find out how I can work with it, because I do not want to do it for memorable efficiency (I can reuse archived bitmap later) This is my way What I describe:

  personal bitmap decodeFileToPreferredSize (filef) {bitmap b = empty; {// decode image size Log.i ("bitmap", "imported image size:" + f.length () + "bytes"); Bitmapfile Option o = new bitmapfile Option (); O.inJustDecodeBounds = True; BitmapfinderDiscoverFile (FAAA.S.O.O.O.O.L.O.T.), O); // Check that the user defined the custom image size int scale = 1; If (pref_height! = -1 & amp; pref_width! = -1) {if (o.outHeight> gt; pref_height || o.outwidth & gt; pref_width} {scale = (Math) Math.pow (2, (Int) Math. (Mathematics.log (pref_width / (double) math.max (oh oh, o overview)) / Math log (0.5));}} // point with dot bitmapfactor. O2 = new bitmapfactor option (); O2.in sample size = scale; b = bitmapfile.dicodefile (FAAAASO.O.O.O..T.), O2); String name = "image_" + system syntetime milliseus () + ".jpg"; File file = new file (environment .getExternalStorageDirectory (), name); FileOutputStream Out = New FileOutputStream (File); B.compress (bitmap.compress format.jpeg, 100, out); Out.close (); Logs. I ("bitmap", "exported image size:" + file.length () + "bytes"); } Hold (exception e) {b = null; } Return B; }   

UPDATE I have seen density on two image files. There is a 72 dpi density for the width and height of a person who came with the intention of the camera. The image file created with the above method has 96 dpi density for width and height. It shows that the size of a 0.5 MBIET image coming in the form of camera has changed to approximately 2.5 MBAT in my above method because the rescale factor is (96/72) * 2 ~ = 2.5 For some reason, I do not take the density of the vs. bitmap image that came from the camera. I tried to install the density with all the variations of the bitmapfactory. Option. Also I tried to change bitmap density with bitmap.setDensity (int dpi); But there is still no effect. Therefore, my new question is that there is a way to define bitmap density when the image is stored.

Thanks in advance.

I had a similar problem when I downloaded images from the web, Used more space on the SD when downloaded. I think the issue is that the Bitmapfactor saves images in any kind of non-friendly format.

My operation was to use a bitmapfactor instead:

  try {try = is your input stream; // Consider reading the stream twice and going back to bitmap Os = youroutputstream; Byte data [] = new byte [4096]; integer number; Whereas ((count = is.read (data)) = -1) {os.write (data, 0, count); }} Hold (exception e) {e.printStackTrace (); } Finally {if (!! = Null) is {. } If (os! = Null) {os.close (); }}} Hold (IOException e) {e.printStackTrace (); }    

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -