This is a relatively simple problem, but also we often back to the problem, that is, in the development process of Android, how to transfer memory card pictures or other files, and then processing this file, because we can not process the original file, is currently doing a picture of the Android project, So use this knowledge, and share it with you.
private void String2file () {tempfiles = new file[resultfilelist.size ()];p assfilemap = new hashmap<string, file> (); for (int i = 0; i < resultfilelist.size (); ++i) {String name = Resultfilelist.get (i). substring (Resultfilelist.get (i). LA Stindexof ("/") + 1); name = Getcachedir (mcontext) + "/" + name; File File = new file (Resultfilelist.get (i)); Tempfiles[i] = new file (name); Uri uri = Uri.fromfile (tempfiles[i]), try {Bitmap Bitmap = decodefile (file, +), if (!tempfiles[i].exists ()) {tempfiles[ I].createnewfile ();} FileOutputStream out = new FileOutputStream (tempfiles[i]); Bitmap.compress (Bitmap.CompressFormat.JPEG, up, out); O Ut.flush (); Out.close ();p assfilemap.put (Tempfiles[i].getabsolutepath (), tempfiles[i]);//Tempfiles[i].delete ();} catch (Exception e) {//Todo:handle exception}}}private Bitmap decodefile (File F, int bmpsize) {if (f = = NULL | |!f.exist S ()) return null;try {bitmapfactory.options o = new Bitmapfactory.options (); o.injustdecodebounds = True;o. Inpreferredconfig = bitmap.confIg. argb_8888;o.ininputshareable = True;o.inpurgeable = true; Bitmapfactory.decodestream (new FileInputStream (f), NULL, O), final int required_size = Bmpsize;int Width_tmp = o.outwidth , height_tmp = O.outheight;int scale = 1;if (width_tmp > Required_size | | height_tmp > Required_size) {if (width_tmp > height_tmp) {scale = Width_tmp/required_size,} else {scale = height_tmp/required_size;}} Decode with insamplesizebitmapfactory.options O2 = new Bitmapfactory.options (); o2.insamplesize = Scale;o2. Inpreferredconfig = Bitmap.config.argb_8888;o2.ininputshareable = True;o2.inpurgeable = true; Bitmap bmp = Bitmapfactory.decodestream (new FileInputStream (f), NULL, O2); return bmp;} catch (FileNotFoundException e) {}return null;}
We first take out the original file, the specific processing for him, the example, you can compress what, and then the processed pictures into the new file, so that the original file will not be affected.
This situation is very common in the compression of local images, hoping to give you a little revelation.
Android turns the image or other files in the memory card into other paths