Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Capture Image:</strong></p> <pre><code> public class Camera extends Activity { private static final int CAMERA_REQUEST = 1888; private String selectedImagePath; WebView webview; String fileName = "capturedImage.jpg"; private static Uri mCapturedImageURI; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent cameraIntent = new Intent(ACTION_IMAGE_CAPTURE); startActivityForResult(cameraIntent, CAMERA_REQUEST); } @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_OK) { if (requestCode == CAMERA_REQUEST) { Bitmap photo = (Bitmap) data.getExtras().get("data"); ByteArrayOutputStream bytes = new ByteArrayOutputStream(); photo.compress(Bitmap.CompressFormat.JPEG, 40, bytes); Random randomGenerator = new Random();randomGenerator.nextInt(); String newimagename=randomGenerator.toString()+".jpg"; File f = new File(Environment.getExternalStorageDirectory() + File.separator + newimagename); try { f.createNewFile(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } //write the bytes in file try { fo = new FileOutputStream(f.getAbsoluteFile()); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { fo.write(bytes.toByteArray()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } uri=f.getAbsolutePath(); //this is the url that where you are saved the image } } </code></pre> <p><strong>Choose Image:</strong></p> <pre><code> public class ChoosePicture extends Activity { private static final int SELECT_PICTURE = 1; private String selectedImagePath; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); webview=(WebView)findViewById(R.id.webView1); Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_OPENABLE); startActivityForResult(intent, SELECT_PICTURE); } @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_OK) { if (requestCode == SELECT_PICTURE) { Uri selectedImageUri = data.getData(); selectedImagePath = getPath(selectedImageUri); try { FileInputStream fileis=new FileInputStream(selectedImagePath); BufferedInputStream bufferedstream=new BufferedInputStream(fileis); byte[] bMapArray= new byte[bufferedstream.available()]; bufferedstream.read(bMapArray); Bitmap bMap = BitmapFactory.decodeByteArray(bMapArray, 0, bMapArray.length); //this is the image that you are choosen if (fileis != null) { fileis.close(); } if (bufferedstream != null) { bufferedstream.close(); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } } } public String getPath(Uri uri) { String[] projection = { MediaStore.Images.Media.DATA }; Cursor cursor = managedQuery(uri, projection, null, null, null); int column_index = cursor .getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return cursor.getString(column_index); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload