- Where Developers Learn, Share, & Build Careers
I'm trying to store a bitmap (which I've already read from a file) in a better shape After decoding 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 which 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 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: 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; }
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.
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
Post a Comment