Posts

Showing posts with the label share image

How to share an image from Drawable folder?

To share an image in drawable folder of your sketchware android project, first save the image in app cache and then share the saved image using it's Uri. The code to be used is provided below. 1. First add the image (my_image.jpg) to be shared in your Sketchware android project using image manager. 2. Add a Button button1 which will act as share button. 3. In event button1 onClick, use add source directly block and add following code: Bitmap bitmap= BitmapFactory.decodeResource(getResources(),R.drawable.my_image); String path = getExternalCacheDir()+"/shareimage.jpg"; java.io.OutputStream out = null; java.io.File file=new java.io.File(path); try { out = new java.io.FileOutputStream(file); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out); out.flush(); out.close(); } catch (Exception e) { e.printStackTrace(); } path=file.getPath(); Uri bmpUri = Uri.parse("file://"+path); Intent shareIntent = new Intent(); shareIntent = new Intent(android.conte...

How to create an image from a View and save it in Sketchware

Image
Using codes in add source directly block in Sketchware, we can create bitmap images from any View (like EditText, TextView, LinearLayout, WebView, etc.) in android app. The bitmap images can then be saved to externalcache or to external storage if the permissions to WRITE EXTERNAL STORAGE is added. To Create an app which can create images from any View and share it, follow the steps given below. 1. Start a new Sketchware project. In VIEW area add an LinearLayout ( linear1 ) containing things to be converted to an image, and a Button ( button1 ) for converting linear1 to image.. If you want to preview the image add an ImageView also. 2. In LOGIC area of project, create a More Block  saveView[View:view]. Here use an add source directly block and add following code: Bitmap returnedBitmap = Bitmap.createBitmap(_view.getWidth(), _view.getHeight(),Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(returnedBitmap); android.graphics.drawable.Drawable bgDrawable =_view.get...