Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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()
- }
- });
- }
- }
Advertisement