• android 显示大图片


    //MianActivity

    package com.example.showsmallandbigpic;
    import android.app.Activity;
    import android.content.Intent;
    import android.graphics.Bitmap;
    import android.graphics.BitmapFactory;
    import android.os.Bundle;
    import android.view.Display;
    import android.widget.ImageView;
    
    public class picActivity extends Activity {
        private ImageView ivTest;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
            setContentView(R.layout.pic);
            ivTest=(ImageView)findViewById(R.id.iv);
            Intent intent=getIntent();
            String s=intent.getStringExtra("type");
            if(s.equals("small")){
                Bitmap bm=BitmapFactory.decodeResource(getResources(), R.drawable.small);
                ivTest.setImageBitmap(bm);
            }
            else{
                Display currenDisplay=getWindowManager().getDefaultDisplay();
                int dw=currenDisplay.getWidth();
                int dh=currenDisplay.getHeight();
                BitmapFactory.Options bmpFactoryOptions=new BitmapFactory.Options();
                bmpFactoryOptions.inJustDecodeBounds=true;        
                Bitmap bmpBitmap=BitmapFactory.decodeResource(getResources(), R.drawable.big,bmpFactoryOptions);
                int heightRatio=(int)Math.ceil(bmpFactoryOptions.outHeight/(float)dh);
                int widthRatio=(int)Math.ceil(bmpFactoryOptions.outWidth/(float)dw);
                System.out.println("heightRation="+heightRatio);
                System.out.println("widthRatio="+widthRatio);            
                if(heightRatio>1&&widthRatio>1){
                    if (heightRatio>widthRatio)
                        bmpFactoryOptions.inSampleSize=heightRatio;
                
                else {
                    bmpFactoryOptions.inSampleSize=widthRatio;
                }
                }
                bmpFactoryOptions.inJustDecodeBounds=false;
                Bitmap bmp=BitmapFactory.decodeResource(getResources(), R.drawable.big,bmpFactoryOptions);
                ivTest.setImageBitmap(bmp);
                
            }
        }
        
    
    }

    //picActivity

    package com.example.showsmallandbigpic;
    import android.app.Activity;
    import android.content.Intent;
    import android.graphics.Bitmap;
    import android.graphics.BitmapFactory;
    import android.os.Bundle;
    import android.view.Display;
    import android.widget.ImageView;

    public class picActivity extends Activity {
        private ImageView ivTest;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
            setContentView(R.layout.pic);
            ivTest=(ImageView)findViewById(R.id.iv);
            Intent intent=getIntent();
            String s=intent.getStringExtra("type");
            if(s.equals("small")){
                Bitmap bm=BitmapFactory.decodeResource(getResources(), R.drawable.small);
                ivTest.setImageBitmap(bm);
            }
            else{
                Display currenDisplay=getWindowManager().getDefaultDisplay();
                int dw=currenDisplay.getWidth();
                int dh=currenDisplay.getHeight();
                BitmapFactory.Options bmpFactoryOptions=new BitmapFactory.Options();
                bmpFactoryOptions.inJustDecodeBounds=true;        
                Bitmap bmpBitmap=BitmapFactory.decodeResource(getResources(), R.drawable.big,bmpFactoryOptions);
                int heightRatio=(int)Math.ceil(bmpFactoryOptions.outHeight/(float)dh);
                int widthRatio=(int)Math.ceil(bmpFactoryOptions.outWidth/(float)dw);
                System.out.println("heightRation="+heightRatio);
                System.out.println("widthRatio="+widthRatio);            
                if(heightRatio>1&&widthRatio>1){
                    if (heightRatio>widthRatio)
                        bmpFactoryOptions.inSampleSize=heightRatio;
                
                else {
                    bmpFactoryOptions.inSampleSize=widthRatio;
                }
                }
                bmpFactoryOptions.inJustDecodeBounds=false;
                Bitmap bmp=BitmapFactory.decodeResource(getResources(), R.drawable.big,bmpFactoryOptions);
                ivTest.setImageBitmap(bmp);
                
            }
        }
        

    }

    //activity_main.xml

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context=".MainActivity" >
    
        <Button
            android:id="@+id/small"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:layout_marginLeft="107dp"
            android:layout_marginTop="103dp"
            android:text="small" />
    
        <Button
            android:id="@+id/big"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/small"
            android:layout_centerVertical="true"
            android:text="big" />
    
    </RelativeLayout>

    //pic.xml

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    
        <ImageView
            android:id="@+id/iv"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:src="@drawable/ic_launcher" />
    </RelativeLayout>
  • 相关阅读:
    PY个树状数组
    PY 个板子计划【雾
    PY个欧拉筛
    【NOI2007】项链工厂 ——老题新做.jpg
    Min-Max 容斥的证明
    51nod 1963 树上Nim
    ●BZOJ 3566 [SHOI2014]概率充电器
    ●BZOJ 3640 JC的小苹果
    ●BZOJ 1444 [Jsoi2009]有趣的游戏
    ●Joyoi Dotp 驱逐猪猡
  • 原文地址:https://www.cnblogs.com/sklww/p/3659469.html
Copyright © 2020-2023  润新知