roko_man icon

Gallery Image To file

roko_man | PRO | 01/14/18 07:31:23 AM UTC | 0 ⭐ | 10513 👁️ | Never ⏰ | []
Kotlin |

1.66 KB

|

None

|

0 👍

/

0 👎

   val selectedImage = data?.getData()
            val myPath :String = ImageFilePath.getPath(this@MainActivity, selectedImage)
            val bitmap : Bitmap = flipImage(myPath)
            doAsync {
                //========== create file =======================
                val random = Random()
                val randomN = random.nextInt(1421200000)
                //create a file to write bitmap data
                filez = File(this@MainActivity.getCacheDir(), "image" + bitmap.getByteCount() + "" + randomN + ".png")
                filez?.createNewFile()
                //Convert bitmap to byte array
                //  Bitmap bitmap = your bitmap;
                val bos = ByteArrayOutputStream()
                bitmap.compress(Bitmap.CompressFormat.PNG, 0 /*ignored for PNG*/, bos)
                val bitmapdata = bos.toByteArray()
                //write the bytes in file
                val fos = FileOutputStream(filez)
                fos.write(bitmapdata)
                fos.flush()
                fos.close()
                uiThread {
 
                    Glide.with(this@MainActivity).load(filez).into(dialogUserImg);
                    //upload image
                    MyApplicationClass.instance.showProgressBar(act)
                    presenter?.interactor?.uploadImage(file = filez!!,activity = act,repeatTryingIfThereIsErrorOnServer = true, callBack = object : MainActivityInteractorInterface.cancelOrderSucess{
                        override fun clickHere() {
                            MyApplicationClass.instance.progressDialog.dismiss()
                        }
                    });
                }
            }

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎