0

I get this error on the 3rd line of code in Eclipse:

The method createScaledBitmap(Bitmap, int, int, boolean) in the type Bitmap is not applicable for the arguments (int, int, int, boolean)

Here is the code:

int newWidth = myWallpaperManager.getDesiredMinimumWidth();
int newHeight = myWallpaperManager.getDesiredMinimumHeight();

Bitmap resizedBitmap = Bitmap.createScaledBitmap(R.drawable.kabacloseup, newWidth, newHeight, false);

myWallpaperManager.setResource(resizedBitmap);

Can you tell me how to make createScaledBitmap accept the arguments?

I also get this error on the 4th line:

The method setResource(int) in the type WallpaperManager is not applicable for the arguments (Bitmap)

Update:

BitmapFactory.Options opt = new BitmapFactory.Options();
opt.outWidth = myWallpaperManager.getDesiredMinimumWidth();
opt.outHeight = myWallpaperManager.getDesiredMinimumHeight();
Bitmap b = BitmapFactory.decodeResource(context.getResources(), R.drawable.kabacloseup, opt);

try {
    myWallpaperManager.setBitmap(b);
    myCurrentImageName = "kabacloseup";

} catch (IOException e) {
    e.printStackTrace();
}
Emad-ud-deen
  • 4,734
  • 21
  • 87
  • 152

4 Answers4

2

You have used Resource id(R.drawable.kabacloseup which is int) instead of Bitmap in createScaledBitmap(Bitmap, int, int, boolean) method.

WallpaperManager setResource(int resid) method takes resource id, not bitmap.

Walid Hossain
  • 2,724
  • 2
  • 28
  • 39
1

Try this

BitmapFactory.Options opt = new BitmapFactory.Options();
opt.outWidth = myWallpaperManager.getDesiredMinimumWidth();
opt.outHeight = myWallpaperManager.getDesiredMinimumHeight();
Bitmap b = BitmapFactory.decodeResource(context.getResources(), R.drawable.kabacloseup, opt);
rciovati
  • 27,603
  • 6
  • 82
  • 101
  • Hi, I tried the code but the image is still zoomed in. Is there any more code I need to add? The new code is now in the "Update" section of my post. – Emad-ud-deen Nov 03 '11 at 13:08
  • Thanks for the reply. No not yet because the WindowManager is zooming in the image. Maybe only the people who created the Android system know the secret because they have an app that you can select from the same list that pops up when you select widgets called "Wallpaper" and that allows you to set the desktop wallpaper and it does not zoom it in. I also see many commercial apps out there that also do the same thing without that zoom problem. Hopefully you can find the secret coding for me. – Emad-ud-deen Nov 04 '11 at 09:42
0

I think you want to do this : myWallpaperManager.setImageBitmap(resizedBitmap); nop ?

for the Bitmap.createScaledBitmap(... you can't pass R.drawable.kabacloseup as an argument, you have to retrieve it as a bitmap before : BitmapFactory.decodeResource(getResources(), R.drawable.kabacloseup)

hope it helps

Mathieu de Brito
  • 2,536
  • 2
  • 26
  • 30
  • Hi Harry and everyone else. Thanks for all the replies. Please look at the new code I tried. The image still shows zoomed in. Looks like something is still missing to get that image the correct size. – Emad-ud-deen Nov 03 '11 at 13:21
  • Looks like the WallpaperManager is zooming in the wallpaper images. Is there a way to stop it from doing that? – Emad-ud-deen Nov 03 '11 at 14:37
0

You need to create a Bitmap from your drawable first:

Resources res = context.getResources();
Bitmap b = BitmapFactory.decodeResource(res, R.drawable.icon);

And then use it in Bitmap.createScaledBitmap(). Hope this helps.

Egor
  • 39,695
  • 10
  • 113
  • 130