Save any image in phone storage

 


 The tutorial is how to save an image to gallary from imageview in sketchware.

Create a new project,add an imageview imageview1,two buttons button1 and button 2.Change weidth and height of imageview1 as match_parent and 500 dp.

In logic area create a more block






Bitmap returnedBitmap = Bitmap.createBitmap(_view.getWidth(), _view.getHeight(),Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(returnedBitmap); android.graphics.drawable.Drawable bgDrawable =_view.getBackground(); if (bgDrawable!=null) { bgDrawable.draw(canvas); } else { canvas.drawColor(Color.WHITE); } _view.draw(canvas); java.io.File pictureFile = new java.io.File(Environment.getExternalStorageDirectory() + "/Download/image.png"); if (pictureFile == null) { showMessage("Error creating media file, check storage permissions: "); return; } try { java.io.FileOutputStream fos = new java.io.FileOutputStream(pictureFile); returnedBitmap.compress(Bitmap.CompressFormat.PNG, 100, fos); fos.close(); showMessage("Image Saved successfully"); } catch (java.io.FileNotFoundException e) { showMessage("File not found: " + e.getMessage()); } catch (java.io.IOException e) { showMessage("Error accessing file: " + e.getMessage()); }


In button 1 on click event add the blocks


Save and run the project.



Comments

Popular posts from this blog