Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.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
Android 如何使用毕加索库在ImageView上放大和调整图像_Android_Picasso - Fatal编程技术网

Android 如何使用毕加索库在ImageView上放大和调整图像

Android 如何使用毕加索库在ImageView上放大和调整图像,android,picasso,Android,Picasso,我想问你们安卓图书馆中是否有来自square的“毕加索”:“任何图像功能中心都可以放大,以使我的图像适应所有设备。例如,这是我的Galaxy note 2上的我的应用程序: 是否有任何属性或方法可以放大图像并适应毕加索的画框 图像属性: ImageView image; String currentUrl="http://mw2.google.com/mw-panoramio/photos/medium/48958465.jpg"; image = (ImageView) v.findVi

我想问你们安卓图书馆中是否有来自square的“毕加索”:“任何图像功能中心都可以放大,以使我的图像适应所有设备。例如,这是我的Galaxy note 2上的我的应用程序:

是否有任何属性或方法可以放大图像并适应毕加索的画框

图像属性:

ImageView image;

String currentUrl="http://mw2.google.com/mw-panoramio/photos/medium/48958465.jpg";

image = (ImageView) v.findViewById(R.id.place_image);
Picasso.with(v.getContext())
.load(currentUrl)
.error(R.drawable.benitomussolinimarker)
.into(image);

Picasso.with(this)
.load(currentUrl)
.into(target);

private Target target = new Target()
{
    @Override
     public void onBitmapLoaded(final Bitmap bitmap, Picasso.LoadedFrom from) 
    {
     new Thread(new Runnable() 
     {
         @Override
         public void run() 
         {           

             File file = new File(Environment.getExternalStorageDirectory().getPath() +"/actress_wallpaper.jpg");
             try 
             {
                 file.createNewFile();
                 FileOutputStream ostream = new FileOutputStream(file);
                 bitmap.compress(CompressFormat.JPEG, 75, ostream);
                 ostream.close();
             } 
             catch (Exception e) 
             {
                 e.printStackTrace();
             }

         } //public void run
     }).start();
    }

    @Override
    public void onBitmapFailed(Drawable arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onPrepareLoad(Drawable arg0) {
        // TODO Auto-generated method stub

    }
};
ImageView XML:

<ImageView
    android:id="@+id/place_image"
    android:layout_width="fill_parent"
    android:layout_height="150dp"
    android:layout_marginBottom="5dp"
    android:adjustViewBounds="true"
    android:background="#222222"
    android:src="@drawable/ic_launcher"/>


非常感谢。

您可以根据设备的高度和宽度调整图像大小

DisplayMetrics displaymetrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
        int height = (displaymetrics.heightPixels * 40) / 100;
        int width = displaymetrics.widthPixels;

        ImageView qImage = new ImageView(this);
        Picasso.with(this)
                .load(ServerURL.BASE_URL + "image_url")
                .placeholder(R.drawable.ic_rectangle_logo)
                .error(R.drawable.ic_rectangle_logo).resize(width, height)
                .into(qImage);
我使用.fit().centerCrop()解决了此问题,我的代码如下:

String currentUrl="http://upload.wikimedia.org/wikipedia/commons/5/50/Casa_Natale_Benito_Mussolini_(1).jpg";
image = (ImageView) v.findViewById(R.id.place_image);

Picasso.with(v.getContext())
.load(currentUrl)
.error(R.drawable.marker)  
.fit().centerCrop() // allarga l'immagine
.into(image); 
这是我的新屏幕^^


您为imageview设置了什么比例类型?@blackbelt我用我设置的属性和imageview的xml编辑我的问题:)@blackbelt我需要一个保持图像比例的resize属性。例如,如果我加载一个超大的图像…5000 x 3000,他应该调整图像大小,但考虑图像的比例…我不能使用。fit()我对毕加索没有经验,但要缩放位图,可以使用
BitmapFactory的
inSampleSize
属性。选项
@blackbelt我解决了我的问题,现在我将更新答案,非常感谢!@AshvinSAshok我解决了,现在我将用解决方案编辑:)@AshvinSAshok抱歉,我解决了,但不是用你的解决方案。但是你的解决方案也是正确的,不管怎样,我的解决方案更实用。