I'm trying to build a live wallpaper on Android 2.1 and I cannot figure out how to make a rectangular with x-repeatable bitmap.
Bitmap backWaveImage = BitmapFactory.decodeResource(res, R.drawable.test);
BitmapDrawable backWave = new BitmapDrawable(backWaveImage);
backWave.setTileModeX(TileMode.REPEAT);
backWave.setBounds(0, this.horizon,
this.width, this.horizon + backWaveImage.getHeight());
backWave.draw(c);
where c - is canvas. This code produces nothing.
If I add backWave.setTileModeY(TileMode.REPEAT);
I get the following:
Image seems to be incorrectly scaled or smth. I've got picture in drawable dir, so it's being upscaled.
If I draw a single image (without BitmapDrawable
) everything looks fine. I've played with Gravity, with various TileModes. I've even tried to use Shader
, but nothing helped.
This issue makes me crazy. Please, help.
2 WarrenFaith
There's not much to show. I've got a basic drawFrame() function from CubeLiveWallpaper demo. I believe it works fine.
I've done more tests. This time 5x5 red square with white center.
backWave.setTileModeX(TileMode.REPEAT);
backWave.setGravity(Gravity.LEFT | Gravity.TOP);
backWave.setTileModeY(TileMode.REPEAT);
This code produces the following:
Square is being upscaled to 8x8 pixels, that's ok, but it's definitely misaligned.
backWave.setTileModeX(TileMode.REPEAT);
backWave.setGravity(Gravity.LEFT | Gravity.TOP);
backWave.setTileModeY(TileMode.CLAMP);
gets me something unexpected:
Well, I've figured it out.
My picture is 10x10 pixels. When I use:
backWave.setBounds(0, 486, 480, 496);
I get the nasty image. When, I use:
backWave.setBounds(0, 480, 480, 490);
everything is fine.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.