android live wallpaper rescaling

后端 未结 2 2051

I am learning how to make live wallpapers, but I have a dilemma I\'m sure all who start off have as well.

There is so many resolution screen sizes, how can I just m

2条回答
  •  猫巷女王i
    2020-12-01 18:04

    I've used this code snippet to scale one image to fit on different screen sizes.

    Bitmap image1, pic1;
    image1 = BitmapFactory.decodeResource(getResources(), R.drawable.image1);
    float xScale = (float) canvas.getWidth() / image1.getWidth();
                    float yScale = (float) canvas.getHeight() / image1.getHeight();
                    float scale = Math.max(xScale, yScale); //selects the larger size to grow the images by
    
                    //scale = (float) (scale*1.1); //this allows for ensuring the image covers the whole screen.
    
                    scaledWidth = scale * image1.getWidth();
                    scaledHeight = scale * image1.getHeight();
    
                        pic1 = Bitmap.createScaledBitmap(image1, (int)scaledWidth, (int)scaledHeight, true);
    

    Make sure that the edges don't contain vital information as it will be scaled out of the picture on some screen ratios.

提交回复
热议问题