The example provided below shows how to Convert LinearView Into Image view In SketchWare.
So Let's Follow Me.
1. First of all Add "Linear" In View Area and add a "Button" according to image below.
2. Go To "More Block" Option And add More block according to image below.
3. After adding more block Then set in more block Add Source directly component and copy codes below and paste copy codes into "Add Source directly" component according to image.
Copy Codes
_______________________________
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/myimage.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 in /Download/ folder");
} catch (java.io.FileNotFoundException e) {
showMessage("File not found: " + e.getMessage()); } catch (java.io.IOException e) {
showMessage("Error accessing file: " + e.getMessage());
}
_______________________________
4. after that go to View option and then button and set blocks according to image below.
So Let's Follow Me.
Converted View |
1. First of all Add "Linear" In View Area and add a "Button" according to image below.
2. Go To "More Block" Option And add More block according to image below.
3. After adding more block Then set in more block Add Source directly component and copy codes below and paste copy codes into "Add Source directly" component according to image.
Copy Codes
_______________________________
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/myimage.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 in /Download/ folder");
} catch (java.io.FileNotFoundException e) {
showMessage("File not found: " + e.getMessage()); } catch (java.io.IOException e) {
showMessage("Error accessing file: " + e.getMessage());
}
_______________________________
4. after that go to View option and then button and set blocks according to image below.
Post a Comment