Hello Developers. In this blog post, am going to explain the concept of saving your images in different qualities and formats, all using sketchware pro. The formats include PNG and JPEG. You will be able to learn how to add more formats at the end of the procedure.
Before you start reading this article, you can decide to Download the project to save time.
1: Have a white plain background linear, or of any colour you like and set its orientation to vertical and gravity to centre.
After that drag an edittext, imageview and a button and customise them as you like. You will notice that all these widgets will automatically fix at the centre of your linear. Once you're done, you'll get something like this :
The imageview here is set to weight 1, so it would occupy a large area in the linear. |
2: Create a moreblock and name it anything. While still editing your moreblock, click variables and add imageview from view, two strings namely 'path' and 'name' and lastly a number variable with the name 'quality'.
Once done, you will have a moreblock looking like this :
In your moreblock, add a 'write string to file path' block. You will find it in files. Next drag an 'add source directly' block from operator and paste this code in it :
try{
BitmapDrawable _imageviewBD = (BitmapDrawable) _imageview.getDrawable();
Bitmap _imageviewB = _imageviewBD.getBitmap();
java.io.FileOutputStream _imageviewFOS = null;
java.io.File _imageviewF = Environment.getExternalStorageDirectory();
java.io.File _imageviewF2 = new java.io.File(_path);
_imageviewF2.mkdirs();
String _imageviewFN = _name;
java.io.File _imageviewF3 = new java.io.File(_imageviewF2, _imageviewFN);
_imageviewFOS = new java.io.FileOutputStream(_imageviewF3);
_imageviewB.compress(Bitmap.CompressFormat.JPEG, (int) _quality, _imageviewFOS);
_imageviewFOS.flush();
_imageviewFOS.close();
Intent _imageviewI = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
_imageviewI.setData(Uri.fromFile(_imageviewF)); sendBroadcast(_imageviewI);
}catch(Exception e){
}
try {
android.media.MediaScannerConnection.scanFile(MainActivity.this,new String[]{new java.io.File(_path + _name).getPath()}, new String[]{"image/jpeg"}, null);
} catch(Exception e) {}
try {
android.media.MediaScannerConnection.scanFile(MainActivity.this,new String[]{new java.io.File(_path + _name).getPath()}, new String[]{"image/png"}, null);
} catch (Exception e) {}
3: Create a dialog component. I hope you are familiar in doing so. Name it anything. Here's a quick lead :
4: Go to your button that we used in step 1 and go to its click event and do this ;
5: Add a background image to your imageview at main activity.
_ Watch this video below to get a visual on this article.
If you have any questions about this topic, please comment below.
3 Comments
Great bro
ReplyDeleteThank you
ReplyDeleteWelcome back ☺️
ReplyDelete