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

How to enable download in webview in Sketchware apps?

TextInputLayout in Sketchware

Create Stopwatch App in Android using Sketchware

How to integrate Admob Ads in Sketchware project using AIDE?

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

Code for implementing Notifications in Sketchware

A Flash Light App in Sketchware

Create a Stopwatch App using Chronometer in Sketchware

Create app to save all passwords, protected using voice key