zoukankan      html  css  js  c++  java
  • 相机图片VS 图库图片的一些处理方法

    在写小demo 时遇到的方法,也是copy的别人的!在这里贴出来,方便大家参考

    public String getRealPathFromURI(Uri uri) {
    
    		String[] proj = { MediaStore.Images.Media.DATA };
    		// android多媒体数据库的封装接口
    		Cursor cursor = managedQuery(uri, proj, null, null, null);
    		// 获得用户选择的图片的索引值
    		int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    		// 将光标移至开头 ,这个很重要,不小心很容易引起越界
    		cursor.moveToFirst();
    		// 最后根据索引值获取图片路径
    		String path = cursor.getString(column_index);
    		return path;
    	}
    	/** 
    	 *  处理图片  
    	 * @param bm 所要转换的bitmap 
    	 * @param newWidth新的宽 
    	 * @param newHeight新的高   
    	 * @return 指定宽高的bitmap 
    	 */ 
    	 public static Bitmap zoomImg(Bitmap bm, int newWidth ,int newHeight){   
    	    // 获得图片的宽高   
    	    int width = bm.getWidth();   
    	    int height = bm.getHeight();   
    	    // 计算缩放比例   
    	    float scaleWidth = ((float) newWidth) / width;   
    	    float scaleHeight = ((float) newHeight) / height;   
    	    // 取得想要缩放的matrix参数   
    	    Matrix matrix = new Matrix();   
    	    matrix.postScale(scaleWidth, scaleHeight);   
    	    // 得到新的图片   
    	    Bitmap newbm = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, true);   
    	    return newbm;   
    	}  
    	/**
    	 *  转化为byte数组 ,压缩
    	 * @param bitmap
    	 * @return byte[]
    	 */
    	public byte[] toByteArray(Bitmap bitmap) {
    		ByteArrayOutputStream baos = new ByteArrayOutputStream();
    		bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
    		byte[] byteArray = baos.toByteArray();
    		return byteArray;
    	}
    
  • 相关阅读:
    开源项目之Android StandOut(浮动窗口)
    小智慧7
    安卓学习
    asp.net学习Request和Response的其他属性
    bash中的转义
    POJ 1833 排列
    Django点滴(四)ORM对象存取
    POJ 1681 Painter's Problem
    linux2.6.32在mini2440开发板上移植(21)之WebServer服务器移植
    [gkk传智]static与多态及向下向上转型,及多态调用总结
  • 原文地址:https://www.cnblogs.com/youmu/p/3200398.html
Copyright © 2011-2022 走看看