Sunday 15 April 2012

android - Save bitmap to file -


I tried to apply the feature back and forth in the Android Fingerprint app. I have tried to use the code below.

Error

  03-26 20: 42: 12.020: W / Systems. Er (28056): java.lang NullPointerException 03-26 20: 42: 12.020: W / Systems. ARR (28056): On Bark Soft. FirstActivity.TextPEGFFile (FirstActivia.JavaN1) 03-26 20: 42: 12.020: W / Systems Er (28056): Baked soft.firstActivity.onOptionsItemSelected (FirstActivity.java.304)   

FirstActivity

  Public Boolean Onoptsim selected (MenuItem item) { Switch (item .getItemId ()) {Case RID. Tolls: ll.setVisibility (LinearLayout.VISIBLE); Back true; Case R.id.import_pics: getPhotos (); Back true; Case R.id.save: toJPEGFile (); Back true; Case R.id.trash: Trash (); Back true; } return false; } Private Zero JPEG File () {// Tudo Auto-Generated Method Stub String Root = Environment.Getensteinstorage Directories (). Toasting (); File myDir = new file (root + "/ saved_image"); MyDir.mkdirs (); Random Generator = New Random (); Int n = 10000; N = Generator. NXT (N); String fname = "image -" + n + ".jpg"; File file = new file (myDir, fname); If (file.exists ()) file.delete (); {FileOutputStream Out = Try New FileOutputStream (File); FinalBitmap.compress (bitmap.compress format.jpeg, 90, out); // Error 341 LINE out.flush (); Out.close (); } Hold (exception e) {e.printStackTrace (); }}   

I do not know where is the wrong. Please help me. thank you in advanced!

finalBitmap.compress (bitmap .compress format.jpeg, 90, out);

As you indicate, that is the error line.

The last billing map has not been initiated.

Alias, this is not a bitmap, it's a zero value. Make sure you load this bitmap first in this variable. finalBitmap = .... // Assign Final Bitmap FinalBitmap.compress (bitmap .compress format.jpeg, 90, out); // Then Save to File

Edit:

Reading from your comment, one way to do this is to, onDraw method :

  canvas.draw bitmap (bitmap, 0, 0, paint); FinalBitmap = bitmap;   

But again, it does not know where you are getting from bitmap, is it another global variable? Maybe you just final

No comments:

Post a Comment