I've done some testing, reading, testing, reading, testing,
reading, and so on, since last night's post, and I have some
updates to add. Perhaps this will be enough information for
someone to be able to help me figure out what's going wrong (at
least, I really hope so!).
I've added code to check the display density
(int odpi = dm.densityDpi;) and, later, changed the code for
resizing the image and added code to set its density to that
of the display:
Bitmap resizedBitmap =
Bitmap.createScaledBitmap(image,newx,newy,false);
resizedBitmap.setDensity(odpi);
where newx and newy are calculated by multiplying the scale
factor (set to the same for x and y to preserve the aspect ratio)
by the original image's width and height, respectively.
As I added these changes, one by one, I saw no change at all in
the wallpaper it produced. I then added code to clear the
wallpaper, and commented out the code that added it back as a
test. I got a default wallpaper (yuck). So I added back the
code to set the wallpaper and it did so again, but still
(obviously) no change....
So I started setting the desired size and density to absurd
values (insanely high, insanely low, etc.). It was when I set
the size VERY low that I discovered something: the image *IS*
being resized...TWICE. The re-resized image was pixelated to
hell and back....resetting it to a more reasonable test size got
rid of that, and it looked "normal" (for low-res) again.
After the changes, tests, etc., the new code is as follows---again,
indentation is reduced for readability:
--------------------------- CUT HERE ---------------------------
// load and resize the original image
Bitmap image = BitmapFactory.decodeResource(getResources(),
mImageIds[info.position]);
// original image size == w,h
int w = image.getWidth();
int h = image.getHeight();
// get display size in pixels
Display display = getWindowManager().getDefaultDisplay();
DisplayMetrics dm = new DisplayMetrics();
display.getMetrics(dm);
int nW = dm.widthPixels;
int nH = dm.heightPixels;
int odpi = dm.densityDpi;
// I thought this might work better...it didn't.
// int nW = manager.getDesiredMinimumWidth();
// int nH = manager.getDesiredMinimumHeight();
// Calculate the scale factor
float sW = (nW) / w;
float sH = (nH) / h;
// do NOT fsck with the aspect ratio: make sure we scale at 1:1
if (sW > sH) sW = sH;
if (sH > sW) sH = sW;
// Now that we have our new scale ratio that protects
// the aspect ratio, multiply it by the original dimens
// to get the NEW image size
int newx = (int) (sW * w);
int newy = (int) (sH * h);
// scale the image by the calculated scale factor
Bitmap resizedBitmap =
Bitmap.createScaledBitmap(image,newx,newy,false);
resizedBitmap.setDensity(odpi);
// Load the resized image as wallpaper
try {
manager.clear(); // test...
manager.setBitmap(resizedBitmap);
} catch (IOException e) {
e.printStackTrace();
}
--------------------------- CUT HERE ---------------------------
It's being resized by my code first. And then, as it's applied
as wallpaper, it's being stretched to a point where it no longer
fits on the screen, and only about 1/3 of the image is actually
shown. It is NOT carried over into the next display, either.
It's the same image, resized first by my code, and then
resized AGAIN by something else, which then sets the
same fragment of the image as the wallpaper on each
display screen.
Can anyone please help me out here?
Later,
--jim
--
73 DE N5IAL (/4) | DMR: So fsck was originally called
[email protected] | something else.
< Running FreeBSD 7.0 > | Q: What was it called?
ICBM / Hurricane: | DMR: Well, the second letter was different.
30.44406N 86.59909W | -- Dennis M. Ritchie, Usenix, June 1998.
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en