Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/340.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将墙纸设置为设备而不进行裁剪或放大_Java_Android - Fatal编程技术网

Java 将墙纸设置为设备而不进行裁剪或放大

Java 将墙纸设置为设备而不进行裁剪或放大,java,android,Java,Android,当我将应用程序中的图像设置为设备的背景时,设备会放大图像并对其进行裁剪,但我不希望这样,我希望将图像设置为相同的大小 下面是一段简短的视频,解释我的意思“只要15秒” 提示:第一个是我的应用,第二个是Zedge应用,同一张照片。 因此,当将图像设置为壁纸时,我希望我的应用程序喜欢edge应用程序 这是我的代码 item_home_image = findViewById(R.id.item_home_image); item_home_image.setOnClickListener(new V

当我将应用程序中的图像设置为设备的背景时,设备会放大图像并对其进行裁剪,但我不希望这样,我希望将图像设置为相同的大小

下面是一段简短的视频,解释我的意思“只要15秒”

提示:第一个是我的应用,第二个是Zedge应用,同一张照片。 因此,当将图像设置为壁纸时,我希望我的应用程序喜欢edge应用程序

这是我的代码

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应用程序设置图像时的图像

public void getBitmapFromURL(字符串路径){
滑翔,滑翔(WaalDetail.这个)
.asBitmap()
.加载(路径)
.into(新的SimpleTarget(){
@凌驾

public void onResourceReady(@NonNull Bitmap resource,@Nullable Transition我找到了一个解决方案,它比这个要好

    // 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();
}

问题不在于图书馆使用过毕加索或glide,我认为这是在比例型墙纸,还有“我使用了你的代码,问题是钢”。
    // 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();
}