Skip to content

Commit

Permalink
System wallpaper background
Browse files Browse the repository at this point in the history
Corrected background image aspect ratio, center the image and crop (cover style resizing)
  • Loading branch information
dvhh committed Apr 23, 2015
1 parent 886e87f commit ce4dfd8
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1566,8 +1566,20 @@ protected void onDraw(Canvas canvas) {
if(mBackgroundDrawable==null) {
canvas.drawRect(0, 0, w, h, backgroundPaint);
}else{
int bw=mBackgroundDrawable.getIntrinsicWidth();
int bh=mBackgroundDrawable.getIntrinsicHeight();
double vratio=1.0*h/bh;
double hratio=1.0*w/bw;
double ratio=hratio;
if(bh*hratio<h) {
ratio=vratio;
}

mBackgroundDrawable.setBounds(0, 0, w, h);
int tw= (int) (bw*ratio);
int th= (int) (bh*ratio);
int lm=(w-tw)/2;
int tm=(h-th)/2;
mBackgroundDrawable.setBounds(lm, tm, lm+tw,tm+th);
mBackgroundDrawable.draw(canvas);

//backgroundPaint.setAlpha(255 - mBackgroundAlpha);
Expand Down

0 comments on commit ce4dfd8

Please sign in to comment.