【问题标题】:not able to zoom images with photoview library无法使用 photoview 库缩放图像
【发布时间】:2018-03-14 05:16:32
【问题描述】:

我正在使用来自herePhotoView 库。它没有给出任何错误,但我无法缩放图像。尝试缩放图像时没有任何反应。我也没有收到来自 build.gradle 的任何错误。我该如何解决?

FullImageActivity.java

public class FullImageActivity extends AppCompatActivity {
    int position;
    int folderPosition;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_full_image);
        Intent i = getIntent();
        PhotoView photoView = (PhotoView) findViewById(R.id.photo_view);


        // Selected image id
        position = i.getExtras().getInt("id");
        folderPosition = i.getExtras().getInt("folderPosition");
        Bundle extras = getIntent().getExtras();
        String value = extras.getString("abc");

        Glide.with(FullImageActivity.this)
                .load(value)
                .skipMemoryCache(false)
                .into(photoView);

        ViewPager mViewPager = (ViewPager) findViewById(R.id.viewpager);
        mViewPager.setAdapter(new TouchImageAdapter(this,al_images, folderPosition));
        mViewPager.setCurrentItem(position);
    }
}

activity_full_image.xml:

<?xml version="1.0" encoding="utf-8"?>

     <LinearLayout
         xmlns:android="http://schemas.android.com/apk/res/android"
         android:id="@+id/jazzy_pager"
         android:layout_width="match_parent"
         android:layout_height="match_parent">


     <android.support.v4.view.ViewPager
         android:id="@+id/viewpager"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content" />

     <com.github.chrisbanes.photoview.PhotoView
         android:id="@+id/photo_view"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:layout_gravity="center"
         android:scaleType="centerCrop"/>


</LinearLayout>

build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion '25.0.3'
    defaultConfig {
        applicationId "com.example.dell_1.Myapp3"
        minSdkVersion 14
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    sourceCompatibility = '1.7'
    targetCompatibility = '1.7'

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
    }
}


dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha7'
    compile 'com.android.support:support-annotations:25.3.1'
    compile 'com.ss.bannerslider:bannerslider:1.8.0'
    compile 'com.github.chrisbanes:PhotoView:2.0.0'
    compile 'com.github.barteksc:android-pdf-viewer:2.7.0-beta.1'
    compile 'com.github.bumptech.glide:glide:3.8.0'
    compile 'com.android.support:design:25.3.1'
    compile 'com.android.support:support-v4'
    compile 'com.squareup.picasso:picasso:2.3.2'
    compile 'com.nineoldandroids:library:2.4.0'
    compile 'com.daimajia.slider:library:1.1.5@aar'
    testCompile 'junit:junit:4.12'
    compile 'org.jetbrains:annotations-java5:15.0'
}

【问题讨论】:

    标签: java android xml pinchzoom android-photoview


    【解决方案1】:

    试试这个代码:

      Glide.with(FullImageActivity.this)
                        .load(value)
                        .asBitmap()
                        .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                        .into(new SimpleTarget<Bitmap>() {
                            @Override
                            public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
                                photoView.setImageBitmap(resource);
                            }
                        });
    

    【讨论】:

    • 我试过上面的clode,还是不能缩放图片
    【解决方案2】:

    尝试使用Picasso 库。

    Picasso.with(context)
        .load(url)
        .placeholder(R.drawable.user_placeholder)
        .error(R.drawable.user_placeholder_error)
        .into(imageView);
    

    this文章

    毕加索下载图像并存储全尺寸图像(在我的情况下 缓存中的图像分辨率为 1160*750),无论何时我们询问 对于相同的图像,它将返回全尺寸图像并调整它们的大小 实时融入 ImageView。

    另一方面,Glide 的工作方式不同。 Glide 下载图像 从给定的 URL,将其调整为图像视图的大小并存储 它到磁盘缓存。

    当 Glide 调整图像大小时,您遇到了缩放问题。所以使用毕加索可能会解决你的问题。

    【讨论】:

    • 我尝试用毕加索代替滑翔,仍然无法缩放图像
    【解决方案3】:

    试试这个方法,对你有帮助

    public class ImageView_Main extends Activity {
    private ImageViewTouch ivLargeImage;
    private Bitmap myBitmap;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.image_view);
    ivLargeImage = (ImageViewTouch) findViewById(R.id.ivLargeImageView);
    
    // if image size is too large.Then scale image.
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    
                    // provide image path for create Bitmap from image.
                    // myBitmap = BitmapFactory.decodeFile( //provide here image file path//);
    //Or
    myBitmap = BitmapFactory.decodeResource(//provider here resource //);
    
    if (options.outWidth > 3000 || options.outHeight > 2000) {
    options.inSampleSize = 4;
    } else if (options.outWidth > 2000 || options.outHeight > 1500) {
    options.inSampleSize = 3;
    } else if (options.outWidth > 1000 || options.outHeight > 1000) {
    options.inSampleSize = 2;
    }
    options.inJustDecodeBounds = false;
    
    myBitmap = BitmapFactory.decodeResource//provider here resource //);
    ivLargeImage.setImageBitmapReset(myBitmap, 0, true);
       }
    }
    

    http://www.theappguruz.com/blog/android-pinch-zoom

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-09-13
    • 1970-01-01
    • 1970-01-01
    • 2017-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多