How Can I convert an imageview to byte array in Android Studio?

前端 未结 1 1585
广开言路
广开言路 2021-02-09 06:40

My goal is to get a picture selected by the user and populate an image view with it. Then, on clicking a button, that image will be sent to a Parse database. I know I have to co

相关标签:
1条回答
  • 2021-02-09 07:24

    Try converting the image view to a bitmap drawable first then get the byteArray:

    ImageView imageView = (ImageView) findViewById(R.id.imageView);
    Bitmap bitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
    byte[] imageInByte = baos.toByteArray();
    //save your stuff
    
    0 讨论(0)
提交回复
热议问题