Saving image from image view to sd card : Android

后端 未结 3 1330
臣服心动
臣服心动 2020-12-16 07:32
testButton.setOnClickListener(new Button.OnClickListener(){

        @Override
        public void onClick(View v) 
        {
                    imageView.setImageB         


        
3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-16 08:01

    Solved, This is how i achieved to save image from ImageView

    /*Variable which holds Image*/
        {ImageView ivBanner = "Initialise It :)";
         FileOutputStream fileOutputStream = openFileOutput("ImageName" + ".jpg", MODE_PRIVATE);
    
         Bitmap bitmap = convertToBitMap(ivBanner.getDrawable(),ivBanner.getWidth(),ivBanner.getHeight());
         bitmap.compress(Bitmap.CompressFormat.JPEG, 85, fileOutputStream);
         File file = getFileStreamPath("ImageName" + ".jpg");
         File f = file.getAbsoluteFile();
         /*Utilise your path whatever way you want*/
         String localPath = f.getAbsolutePath();}
    
         /* Covert Drawable to Bitmap*/
        private Bitmap convertToBitMap(Drawable drawable, int width, int height) {
        Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        drawable.setBounds(0,0,width,height);
        drawable.draw(canvas);
        return bitmap;
    }
    

提交回复
热议问题