开发者

Resize a wallpaper using code?

开发者 https://www.devze.com 2023-04-13 03:38 出处:网络
Can you tell me the best way to resize a home screen wallpaper using code based on wether the device is in portrait or landscape mode?

Can you tell me the best way to resize a home screen wallpaper using code based on wether the device is in portrait or landscape mode?

We wish开发者_如何学编程 to make sure it will work on many devices.

Please provide code samples.

We are currently using this to set the wallpaper:

myWallpaperManager.setResource(R.drawable.thewallpaper);

The wallpaper is also a png file.

Update:

Based on the code from coder_for_life22, I changed it to this:

        try {
            myWallpaperManager.setResource(R.drawable.kabaday1);

            myCurrentImageName = "kabaday1";

            Bitmap myBitmap = BitmapFactory.decodeResource(context.getResources(),
                    R.drawable.kabaday1);

            Bitmap bitmapResized = Bitmap.createScaledBitmap(myBitmap, 600, 300,
                    false);

            myWallpaperManager.setBitmap(bitmapResized);

        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

It scales the image but Android is re-displaying and expanding the image with the same image size as it did before the scale down, only this time the image quality is on the fuzzy side and still seems zoomed in and not showing the entire image that should be scaled down.

Strange behaviour. Maybe there is some more coding I need to add to this so it really scales down and remains sharp. At least I think it should do that because the image should be smaller.

There are many apps out there doing the same thing. I only wish I knew how they are doing it.

Thanks.


You will need to resize the image using this

 Bitmap bitmapResized = Bitmap.createScaledBitmap(src, dstWidth, dstHeight, filter);

 myWallpaperManager.setBitmapResource(bitmapResized);

EDIT: You may also need to change the scaleType of the imageview you are using. by inserting this in your xml where imageview is located.

  android:scaleType = "FIT_CENTER"

OR you can do it programmatically by inserting this in your above code.

myWallpaperManager.setScaleType(ImageView.FIT_CENTER);

That should get rid of the zoomed in look you are getting.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号