I'm trying to make a Wallpaper Application. And I had big trouble during set wallpaper with bitmap. I try to figure out answer for a week.
I want to set Bitmap in to wallpaper like
- avoid crop
- scaleType:fit_center(align center vertical, bitmap's width is strech to full, aspect ratio)
How can I make it?
P.S. And I found that maybe I can use Bitmap.createBitmap, but my try was failed over and over. I have no idea that I should use only WallPaperManager or both Bitmap.createBitmp Too.
static Bitmap createBitmap(Bitmap source, int x, int y, int width, int height, Matrix m, boolean filter)
public void setScreenBitmap(final Bitmap bitmapInputed)
{
final WallpaperManager wpm = WallpaperManager.getInstance(myContext);
final Display display = ((Activity) this.myContext).getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;
try
{
wpm.setBitmap(Bitmap.createScaledBitmap(bitmapInputed, width, height, true));
}
catch (IOException e)
{
Log.e(TAG+".setScreenBitmap", e.toString());
e.printStackTrace();
}
wpm.setWallpaperOffsetSteps(1.0f, 1.0f);
wpm.suggestDesiredDimensions(width, height);
}
0 comments:
Post a Comment