Android Open Source - AndroidImageViewZoom Unscaled Bitmap Operations






From Project

Back to project page AndroidImageViewZoom.

License

The source code is released under:

Copyright (c) 2011 Igor Crevar http://extrafull.com/igorcrevar/ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "...

If you think the Android project AndroidImageViewZoom listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.rogicrew.imagezoom.example;
/*  ww w  .j  a v a 2  s.c o  m*/
import java.lang.reflect.Field;

import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BitmapFactory.Options;
import android.os.Build;

//almost copy paste from http://blog.tomgibara.com/post/190539066/android-unscaled-bitmaps
public abstract class UnscaledBitmapOperations {

    public static final UnscaledBitmapOperations instance;

    static {
      int sdkVersion = Integer.parseInt(Build.VERSION.SDK);
        instance = sdkVersion < 4 ? new Old() : new New();
    }

    public static Bitmap loadFromResource(Resources resources, int resId, BitmapFactory.Options options) {
        return instance.load(resources, resId, options);
    }

    private static class Old extends UnscaledBitmapOperations {

        @Override
        Bitmap load(Resources resources, int resId, Options options) {
            return BitmapFactory.decodeResource(resources, resId, options);
        }

    }

    private static class New extends UnscaledBitmapOperations {

        @Override
        Bitmap load(Resources resources, int resId, Options options) {
            if (options == null) options = new BitmapFactory.Options();
            try {
                Class<?> c = options.getClass();
                Field isScaledField = c.getDeclaredField("isScaled");
                isScaledField.setBoolean(c, true);
            }
            catch (Throwable e) {
                System.err.println(e);
            }
            return BitmapFactory.decodeResource(resources, resId, options);
        }

    }

    abstract Bitmap load(Resources resources, int resId, BitmapFactory.Options options);

}




Java Source Code List

com.rogicrew.imagezoom.ImageViewZoomOptions.java
com.rogicrew.imagezoom.ImageViewZoom.java
com.rogicrew.imagezoom.example.ImageViewZoomExample1Activity.java
com.rogicrew.imagezoom.example.ImageViewZoomTest.java
com.rogicrew.imagezoom.example.UnscaledBitmapOperations.java
com.rogicrew.imagezoom.ontouch.OnTouchInterface.java
com.rogicrew.imagezoom.ontouch.OnTouchMulti.java
com.rogicrew.imagezoom.ontouch.OnTouchSingle.java
com.rogicrew.imagezoom.ontouch.Pointer.java