Skip to content

Instantly share code, notes, and snippets.

@pvllnspk
Last active November 1, 2015 07:50
Show Gist options
  • Select an option

  • Save pvllnspk/b3aa5ad5b79742478426 to your computer and use it in GitHub Desktop.

Select an option

Save pvllnspk/b3aa5ad5b79742478426 to your computer and use it in GitHub Desktop.

Revisions

  1. pvllnspk renamed this gist Nov 1, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. pvllnspk created this gist Dec 6, 2014.
    19 changes: 19 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    private Bitmap combineBitmaps(Bitmap bmp1, Bitmap bmp2, int angle){
    Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth()+2*bmp2.getWidth(), bmp1.getHeight()+2*bmp2.getHeight(), bmp1.getConfig());
    Canvas canvas = new Canvas(bmOverlay);

    int centerX = canvas.getWidth()/2;
    int centerY = canvas.getHeight()/2;

    canvas.drawBitmap(bmp1, centerX-bmp1.getWidth()/2, centerY-bmp1.getHeight()/2, null);

    int R = canvas.getHeight()/2 - bmp2.getHeight()/2;
    int theta = angle-90;
    float x = (float)(centerX + R * Math.cos(theta * Math.PI / 180));
    float y = (float)(centerY + R * Math.sin(theta * Math.PI / 180));

    canvas.rotate(angle,x,y);
    canvas.drawBitmap(bmp2, x - bmp2.getWidth()/2, y - bmp2.getHeight()/2, null);

    return bmOverlay;
    }