Advertisement
Guest User

Untitled

a guest
Feb 14th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. imageView.setOnClickListener(new View.OnClickListener() {
  2.  
  3.  
  4. @Override
  5. public void onClick(View v) {
  6. Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
  7.  
  8. startActivityForResult(cameraIntent, 1);
  9. }
  10. });
  11.  
  12. protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  13. if (requestCode == 1 && resultCode == -1) {
  14. image = (Bitmap) data.getExtras().get("data");
  15. ByteArrayOutputStream stream = new ByteArrayOutputStream();
  16. // Must compress the Image to reduce image size to make upload easy
  17. image.compress(Bitmap.CompressFormat.PNG, 50, stream);
  18. byte[] byte_arr = stream.toByteArray();
  19. // Encode Image to String
  20. encodedString = Base64.encodeToString(byte_arr, 0);
  21. Uri selectedImageUri = data.getData();
  22. img_path = getRealPathFromURI(selectedImageUri);
  23. // Uri tempUri = getImageUri(getApplicationContext(), image);
  24. imageView.setImageBitmap(image);
  25. imageView.setScaleType(ImageView.ScaleType.FIT_XY);
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement