Note that there are some explanatory texts on larger screens.

plurals
  1. POSaving an image with its thumb and showing on imageView android
    primarykey
    data
    text
    <p>I am trying to save an image taken from camera and then storing it on sdCard along with its Thumb also showing this thumb on an imageView. However it gives error at Null pointer</p> <pre><code> imageBitmap = Bitmap.createScaledBitmap(imageBitmap, 40, 40, false); </code></pre> <p>What is wrong?</p> <pre><code> { Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); try { if (title.getText().toString().equals("")) { displayAlert("Please Input Title First","Error!"); } else { Integer val = myMisc.miscId ; String fileName = "image" + "_" + title.getText().toString()+"_" + val.toString(); photo = this.createFile(fileName, ".jpg"); myMisc.filename = photo.getAbsolutePath(); intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo)); startActivityForResult(intent, RESULT_CAMERA_SELECT); } } catch(Exception e) { Log.v("Error", "Can't create file to take picture!"); displayAlert("Can't create file to take picture!","SDCard Error!"); } } public synchronized void onActivityResult(final int requestCode, int resultCode, final Intent data) { if (resultCode == Activity.RESULT_OK) { if (requestCode == RESULT_CAMERA_SELECT) { try { saveImage(); } catch (IOException e) { e.printStackTrace(); } } public static int calculateInSampleSize( BitmapFactory.Options options, int reqWidth, int reqHeight) { // Raw height and width of image final int height = options.outHeight; final int width = options.outWidth; int inSampleSize = 1; if (height &gt; reqHeight || width &gt; reqWidth) { if (width &gt; height) { inSampleSize = Math.round((float)height / (float)reqHeight); } else { inSampleSize = Math.round((float)width / (float)reqWidth); } } return inSampleSize; } public void saveImage() throws IOException { try { FileInputStream is2 = new FileInputStream(photo); final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; Bitmap imageBitmap = BitmapFactory.decodeStream(is2, null, options); options.inSampleSize = calculateInSampleSize(options, 40, 40); options.inJustDecodeBounds = false; imageBitmap = BitmapFactory.decodeStream(is2 ,null, options); imageBitmap = Bitmap.createScaledBitmap(imageBitmap, 40, 40, false); Integer val = myMisc.miscId; String fileName = ".thumbImage" + "_" + title.getText().toString()+ "_" + val.toString(); photo = this.createFile(fileName, ".jpg"); myMisc.thumbFileName = photo.getAbsolutePath(); try { FileOutputStream out = new FileOutputStream(photo); imageBitmap.compress(Bitmap.CompressFormat.PNG, 90, out); } catch (Exception e) { e.printStackTrace(); } is2.close(); Uri uri = Uri.fromFile(photo); photo = null; imageBitmap = null; imageView.setImageURI(uri); }catch(Exception e) { displayAlert("Can't create file to take picture!","SD Card Error"); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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