java部分代码:

package com.xpc.imageviewdemo;import java.io.File;import android.app.Activity;import android.graphics.Bitmap;import android.graphics.BitmapFactory;import android.graphics.Matrix;import android.os.Bundle;import android.os.Environment;import android.util.DisplayMetrics;import android.view.Window;import android.view.WindowManager;import android.widget.ImageView;public class MainActivity extends Activity {ImageView img;String path;String filepath;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);requestWindowFeature(Window.FEATURE_NO_TITLE);getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);//不显示标题栏setContentView(R.layout.activity_main);img = (ImageView) findViewById(R.id.imageView1);File sd = Environment.getExternalStorageDirectory();path = sd.getPath();//获得手机内存storage的位置filepath = path + "/picturereceive/beautiful2.jpg";//storage下需要全屏显示的图片路径(要根据自己手机中需要显示图片路径位置进行修改)File file = new File(filepath);System.out.println("<<<<<<<<<<<<<<<<<<<<<<<<"+filepath);if (file.exists()) {System.out.println("<<<<<<<<<<<<<<<<<<<<<<<4");Bitmap bm = BitmapFactory.decodeFile(filepath);//获得设置路径下图片并编码为Bitmap格式bm = big(bm);//放大图片至全屏System.out.println("<<<<<<<<<<<<<<<<<5");img.setImageBitmap(bm);//设置图片为背景图}else {System.err.println("<<<<<<<<<<<<<404 Not Find");//控制台输出没找到图片}}public Bitmap big(Bitmap bitmap) {  //修改bitmap大小DisplayMetrics dm = new DisplayMetrics();getWindowManager().getDefaultDisplay().getMetrics(dm);  int screenWidth = dm.widthPixels;//获取当前屏幕宽度  int screenHeight = dm.heightPixels;//获取当前屏幕高度float w = (float) screenWidth / bitmap.getWidth();//计算当前图片要全屏幕,宽度需要放大尺寸float h = (float) screenHeight / bitmap.getHeight();//计算当前图片要全屏,高度需要放大尺寸if (w >= h)//选取较小尺寸进行放大w = h;Matrix matrix = new Matrix();matrix.postScale(w, w);//设置宽高放大比例(这里为等比例放大)Bitmap resizeBmp = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(),bitmap.getHeight(), matrix, true);//对现有bitmap进行放大return resizeBmp;}}


xml布局文件代码:

    

注意一定要加上手机读内存权限

在manifest文件中写入  


该项目源代码位置  该项目demo

更多相关文章

  1. android Gallery3D效果
  2. Android(安卓)通过handler和message在子线程里面去更新UI
  3. Android(安卓)恐怖幽灵音效 程序(源码详解)
  4. 【Android】异步加载图片-------不错的思路
  5. android 异步图片处理 工具类
  6. Android图片圆角 用简单的方法实现
  7. Android(安卓)使用decodeFile方法加载手机磁盘中的图片文件
  8. android中图片的拖拉和缩放
  9. Android(安卓)RecyclerView在滑动的时候禁止Glide加载图片,提升用

随机推荐

  1. android sdk 国内镜像地址
  2. android webview开发html5
  3. Android界面——LinearLayout和RelativeL
  4. 重写EditText回车键跳到下一个EditText
  5. Android(安卓)Tips---Android平台常见属
  6. Android(安卓)使用Android(安卓)Studio +
  7. Android(安卓)Tabhost中tab添加数字demo
  8. Android输入框自动提示
  9. android activity设置全屏以及Android获
  10. Android学习笔记3之基本组件API