中心裁剪图像并设置为墙纸

时间:2018-09-09 14:08:04

标签: android android-glide android-wallpaper

我需要通过手势调整图像以将图像缩放到所需位置,或者将图像中心裁切并默认设置为墙纸。

    private void wallpaper() {
    progressBar.setVisibility(View.VISIBLE);
    Toast.makeText(fullscreen.this,"Applying",Toast.LENGTH_LONG).show();
    Glide.with(this).asBitmap()
            .load(imageUrl)
            .apply(new RequestOptions().centerCrop())
            .into(new SimpleTarget<Bitmap>() {
                @Override
                public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
                    WallpaperManager wallManager = WallpaperManager.getInstance(getApplicationContext());
                    try {

                        wallManager.setBitmap(resource);
                        progressBar.setVisibility(View.GONE);
                        Toast.makeText(fullscreen.this, "Wallpaper set successfully", Toast.LENGTH_SHORT).show();
                    } catch (IOException ex) {
                        Toast.makeText(fullscreen.this, "Error!", Toast.LENGTH_SHORT).show();
                    }
                }


            });


}

0 个答案:

没有答案