wisejoy
wisejoy

Reputation: 11

ImageView data to Byte Array Android

I am trying to use parse.com database to upload file and syntax needs me to use byte []. I will write syntax below:

byte[] data = "Working at Parse is great!".getBytes();
ParseFile file = new ParseFile("resume.png", data);
file.saveInBackground();
ParseObject jobApplication = new ParseObject("JobApplication");
jobApplication.put("applicantResumeFile", file);
jobApplication.saveInBackground();

I need to know how to use the first instruction to get ImageView Data in byte[] and upload it.

Upvotes: 0

Views: 1117

Answers (1)

geekCode
geekCode

Reputation: 336

@wisejoy I have an implementation but I think its a little bit different... hope it can help you... cheers!!

            myBitmap = (Bitmap) data.getExtras().get("data");//here I set an image taken by the camera
            imageView.setImageBitmap(myBitmap);//I set it into an image view 
            imageView.buildDrawingCache();
            ByteArrayOutputStream baos = new ByteArrayOutputStream();//and then I convert that image into a byteArray
            myBitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
            byte[] b = baos.toByteArray();

            encondedImage = android.util.Base64.encodeToString(b, Base64.DEFAULT);
            Log.e(TAG, "" + txt);

Upvotes: 1

Related Questions