close
在编写MusicPlayer的过程中,播放歌曲时搜索歌手的图片,并动态地将图片设为当前Activity的背景。当图片大小与屏幕不适应时会导致图片被拉神效果很不好看。比如你的手机分辨率是320X480,而图片的分辨率是320X320,那么,该图片将被拉长。

, TileMode.REPEAT )的方法来设置图片的平铺,但是我没有试验成功,

于是尝试了Bitmap.createBitmap方法。
public
static Bitmap createBitmap (Bitmap source,
int x, int y, int width, int height, Matrix m,
boolean filter)
int x, int y, int width, int height,
boolean filter)
Added in
level 1
Returns an
immutable bitmap from subset of the source bitmap, transformed by
the optional matrix. The new bitmap may be the same object as
source, or a copy may have been made. It is initialized with the
same density as the original bitmap. If the source bitmap is
immutable and the requested subset is the same as the source bitmap
itself, then the source bitmap is returned and no new bitmap is
created.
Parameters
source | The bitmap we are subsetting |
---|---|
x | The x coordinate of the first pixel in source |
y | The y coordinate of the first pixel in source |
width | The number of pixels in each row |
height | The number of rows |
m | Optional matrix to be applied to the pixels |
filter | true if the source should be filtered. Only applies if the matrix contains more than just translation. |
Returns
- A bitmap that represents the
specified subset of source
Throws
IllegalArgumentException | if the x, y, width, height values are outside of the dimensions of the source bitmap. |
---|
各参数含义:
需要注意的是:必须满足条件:x+width<=bitmap.width()(图片源的原始宽度)否则会抛出IllegalArgumentException
下面是思路:
全站熱搜