将壁纸设置为设备上无需裁剪或缩放的模式。

huangapple go评论75阅读模式
英文:

set wallpaper to the device without crop or zoom in

问题

以下是您要翻译的内容:

当我将应用中的图像设置为设备的背景时,设备会放大图像并裁剪它,但我不想要那样,我希望将图像设置为相同的大小。

这里有一个简短的视频解释了我想表达的内容,仅15秒:短视频

提示:第一个是我的应用,第二个是Zedge应用,是相同的照片。
因此,当我将图像设置为壁纸时,我希望我的应用与Zedge应用的效果相似。

这是我的代码

item_home_image = findViewById(R.id.item_home_image);
item_home_image.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        if (checkPermission()) {
            final Intent intent = getIntent();
            String url = intent.getStringExtra("imageUrl");
            Picasso.with(PicassoDisplayImageAdapter.this).load(url).into(new Target() {
                @RequiresApi(api = Build.VERSION_CODES.N)
                @Override
                public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
                    WallpaperManager wallpaperManager = WallpaperManager.getInstance(PicassoDisplayImageAdapter.this);
                    try {
                        wallpaperManager.setBitmap(bitmap);
                    } catch (IOException ex) {
                        ex.printStackTrace();
                    }
                    Toasty.normal(PicassoDisplayImageAdapter.this, "تم تغيير الخلفية بنجاح", Toast.LENGTH_SHORT).show();
                }

                @Override
                public void onBitmapFailed(final Drawable errorDrawable) {
                    Toasty.error(PicassoDisplayImageAdapter.this, "فشل تحميل الصورة", Toast.LENGTH_SHORT).show();
                }

                @Override
                public void onPrepareLoad(final Drawable placeHolderDrawable) {
                    Toasty.normal(PicassoDisplayImageAdapter.this, "جاري التحميل", Toast.LENGTH_SHORT).show();
                }
            });
        }
     }
});

从我的应用中设置图像时的效果
将壁纸设置为设备上无需裁剪或缩放的模式。

从Zedge应用中设置图像时的效果
将壁纸设置为设备上无需裁剪或缩放的模式。

英文:

When I set an image from my app to be as background for the device, the device zoom in the image and crop it, but I don't want that, I want to set the image as the same size for it.

here is a short video explaining what I mean "just 15 sec" the short video

hint: the first one is my app, second is Zedge app, the same photo.
so I want my app to like edge app when set image as wallpaper

Here is my code

item_home_image = findViewById(R.id.item_home_image);
item_home_image.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (checkPermission()) {
final Intent intent = getIntent();
String url = intent.getStringExtra("imageUrl");
Picasso.with(PicassoDisplayImageAdapter.this).load(url).into(new Target() {
@RequiresApi(api = Build.VERSION_CODES.N)
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
WallpaperManager wallpaperManager = WallpaperManager.getInstance(PicassoDisplayImageAdapter.this);
try {
wallpaperManager.setBitmap(bitmap);
} catch (IOException ex) {
ex.printStackTrace();
}
Toasty.normal(PicassoDisplayImageAdapter.this, "تم تغيير الخلفية بنجاح", Toast.LENGTH_SHORT).show();
}
@Override
public void onBitmapFailed(final Drawable errorDrawable) {
Toasty.error(PicassoDisplayImageAdapter.this, "فشل تحميل الصورة", Toast.LENGTH_SHORT).show();
}
@Override
public void onPrepareLoad(final Drawable placeHolderDrawable) {
Toasty.normal(PicassoDisplayImageAdapter.this, "جاري التحميل", Toast.LENGTH_SHORT).show();
}
});
}
}
});

image when set it from my app
将壁纸设置为设备上无需裁剪或缩放的模式。

image when set it from Zedge app
将壁纸设置为设备上无需裁剪或缩放的模式。

答案1

得分: 1

我找到了一个解决方案,而且比这个更好:

// 设置主屏幕壁纸图像
public void setHomeWallpaper() {
    BitmapDrawable bitmapDrawable = ((BitmapDrawable) imageView.getDrawable());
    Bitmap bitmap = bitmapDrawable.getBitmap();
    String bitmapPath = Images.Media.insertImage(getContentResolver(), bitmap, "", null);
    Uri bitmapUri = Uri.parse(bitmapPath);
    Intent intent = new Intent(Intent.ACTION_ATTACH_DATA).setDataAndType(bitmapUri, "image/jpeg")
            .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
            .putExtra("mimeType", "image/jpeg");
    startActivity(Intent.createChooser(intent, getString(R.string.background)));
    Toast.makeText(PicassoDisplayImageAdapter.this, "قم بإختيار التطبيق المناسب لتعيين الصورة", Toast.LENGTH_SHORT).show();
}
英文:

I found a solution, and it is better than this

    // Set Home wallpaper the image
public void setHomeWallpaper () {
BitmapDrawable bitmapDrawable = ((BitmapDrawable) imageView.getDrawable());
Bitmap bitmap = bitmapDrawable.getBitmap();
String bitmapPath = Images.Media.insertImage(getContentResolver(), bitmap, "", null);
Uri bitmapUri = Uri.parse(bitmapPath);
Intent intent = new Intent(Intent.ACTION_ATTACH_DATA).setDataAndType(bitmapUri,  "image/jpeg")
.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
.putExtra("mimeType", "image/jpeg");
startActivity(Intent.createChooser(intent, getString(R.string.background)));
Toast.makeText(PicassoDisplayImageAdapter.this, "قم بإختيار التطبيق المناسب لتعيين الصورة", Toast.LENGTH_SHORT).show();
}

答案2

得分: 0

public void getBitmapFromURL(String path) {

    Glide.with(WaalDetail.this)
            .asBitmap()
            .load(path)
            .into(new SimpleTarget<Bitmap>() {
                @Override
                public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
                    try {
                        WallpaperManager.getInstance(getApplicationContext()).setBitmap(resource);
                        Toast.makeText(WaalDetail.this, "Set wallpaper successfully!", Toast.LENGTH_LONG).show();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }

                }
            });
}

this is works for me perfectly.

英文:
 public void getBitmapFromURL(String path) {
Glide.with(WaalDetail.this)
.asBitmap()
.load(path)
.into(new SimpleTarget&lt;Bitmap&gt;() {
@Override
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition&lt;? super Bitmap&gt; transition) {
try {
WallpaperManager.getInstance(getApplicationContext()).setBitmap(resource);
Toast.makeText(WaalDetail.this, &quot;Set wallpaper successfully!&quot;, Toast.LENGTH_LONG).show();
} catch (IOException e) {
e.printStackTrace();
}
}
});
}

this is works for me perfectly.

huangapple
  • 本文由 发表于 2020年5月31日 05:18:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/62108777.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定