Graphics Draw Bitmap On Canvas

//Add Private
private Context mContext;
private android.content.res.Resources mResources;

//onCreate
mContext = getApplicationContext();
mResources = getResources();

//onButton

// Bitmap to draw on the canvas
Bitmap bitmap = BitmapFactory.decodeResource(
      mResources,
      R.drawable.icon
);

// Define an offset value between canvas and bitmap
int offset = 50;

// Initialize a new Bitmap to hold the source bitmap
Bitmap dstBitmap = Bitmap.createBitmap(
         bitmap.getWidth() + offset * 2, // Width
         bitmap.getHeight() + offset * 2, // Height
         Bitmap.Config.ARGB_8888 // Config
);

// Initialize a new Canvas instance
Canvas canvas = new Canvas(dstBitmap);

// Draw a solid color on the canvas as background
canvas.drawColor(Color.LTGRAY);
canvas.drawBitmap(
       bitmap, // Bitmap
       offset, // Left
       offset, // Top
       null // Paint
);
// Display the newly created bitmap on app interface

imageview1.setImageBitmap(dstBitmap); 

Komentar

Cara pembuatan Apps paling Populer

Create Stopwatch App in Android using Sketchware

TextInputLayout in Sketchware

How to find and​ highlight a word in a text field in Sketchware?

A Flash Light App in Sketchware

How to enable download in webview in Sketchware apps?

Intent - Open File By Type

Code for implementing Notifications in Sketchware

How to share an image from Drawable folder?

ActionBar back button

Animation Transtition Animation