Guest User

Untitled

a guest
May 25th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. public void createImageInImageCenter()
  2. {
  3. Bitmap backgroundBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
  4. Bitmap bitmapToDrawInTheCenter = BitmapFactory.decodeResource(getResources(), R.drawable.ic_action_search);
  5.  
  6. Bitmap resultBitmap = Bitmap.createBitmap(backgroundBitmap.getWidth(),backgroundBitmap.getHeight(), backgroundBitmap.getConfig());
  7. Canvas canvas = new Canvas(resultBitmap);
  8. canvas.drawBitmap(backgroundBitmap, new Matrix(), null);
  9. canvas.drawBitmap(bitmapToDrawInTheCenter, (backgroundBitmap.getWidth() - bitmapToDrawInTheCenter.getWidth()) / 2, (backgroundBitmap.getHeight() - bitmapToDrawInTheCenter.getHeight()) / 2, new Paint());
  10.  
  11. ImageView image = (ImageView)findViewById(R.id.myImage);
  12. image.setImageBitmap(resultBitmap);
  13. }
Add Comment
Please, Sign In to add comment