android加载大图实例

郑州app开发android加载大图实例

为富顺等地区用户提供了全套网页设计制作服务,及富顺网站建设行业解决方案。主营业务为做网站、成都网站设计、富顺网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!

MainActivity.java

package cn.xhhkj.image;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.bitmap;

import android.graphics.bitmapFactory;

import android.graphics.point;

import android.os.bundle;

import android.util.Log;

import android.view.View;

import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {

    private static final String TAG = "结果是";

    private static final int UpDATE_pROGRESS = 0;

    public String path = src="/upload/article1/1.jpg";

    private ImageView iv_image;

    private int screenWidth;

    private int screenHeight;

    bitmap bitmap;

    @Override

    protected void onCreate(bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        init();

    }

    public void init(){

        iv_image = findViewbyId(R.id.iv_pic);

        screenWidth = getWindowManager().getDefaultDisplay().getWidth();

        screenHeight = getWindowManager().getDefaultDisplay().getHeight();

        point outSize = new point();

        getWindowManager().getDefaultDisplay().getSize(outSize);

        Log.d(TAG,"宽度"+outSize.x+"高度"+outSize.y);

    }

    public void loadpic(View view) {

        bitmap bitmap = bitmapFactory.decodeFile(path);

        iv_image.setImagebitmap(bitmap);

        //loadpic2();

    }

    public void loadpic2(){

        bitmapFactory.Options option =new bitmapFactory.Options();

        option.inJustDecodebounds = true;

        int width = option.outWidth;

        int height = option.outHeight;

        if(width>screenWidth||height>screenHeight){

            int widthIndex = Math.round((float)width/(float)screenWidth);

            int heightIndex = Math.round((float)height/(float)screenHeight);

            option.inSampleSize = Math.max(widthIndex, heightIndex);

        }

        option.inJustDecodebounds = false;

        bitmap = bitmapFactory.decodeFile(path, option);

        iv_image.setImagebitmap(bitmap);

    }

    public void loadpic3(){

        bitmapFactory.Options option =new bitmapFactory.Options();

        option.inSampleSize = 1;

        bitmap bitmap = null;

        int i = 1;

        for(;;){

            try {

                option.inSampleSize = i;

                bitmap = bitmapFactory.decodeFile(path, option);

                break;

            } catch (Error e) {

                i*=2;

                System.out.println("i = "+i);

            }

        }

        iv_image.setImagebitmap(bitmap);

    }

}


本文标题:android加载大图实例
标题路径:http://cdiso.cn/article/scssdc.html

其他资讯