压缩位图并将其保存到位图对象

时间:2015-08-07 06:13:07

标签: android bitmap

我是android的初学者。我将Base64图片解码为Bitmap,我需要将其压缩为Outputstream,现在我需要将Bitmap添加到ArrayList

try {
                // Getting JSON Array from URL
             details = json.getJSONArray(TAG_Root);
                for(int i = 0; i < details.length(); i++){
                JSONObject c = details.getJSONObject(i);

                 //Storing  JSON item in a Variable
                String branch = c.getString(TAG_Branch);
                String address = c.getString(TAG_Add);
                String uname = c.getString(TAG_User);
                String photo = c.getString(TAG_Photo);
                System.out.println(photo);

                //decoding and compressing bitmap 
                byte[] imageAsBytes = Base64.decode(photo, Base64.DEFAULT);
                Bitmap bitmap = BitmapFactory.decodeByteArray(imageAsBytes, 0, imageAsBytes.length);

                //bitmap = BitmapFactory.decodeStream(getAssets().open("1024x768.jpg"));
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
                //Bitmap decoded = BitmapFactory.decodeStream(new ByteArrayInputStream(out.toByteArray()));



                 al_branch.add(branch);
                al_add.add(address);
                al_user.add(uname);
                al_photo.add(bitmap);



                }
             System.out.println(al_branch);
              System.out.println(al_photo);  

              custom_list adapter = new custom_list(MainActivity.this, al_branch,al_user,al_add ,al_photo);

0 个答案:

没有答案