当前位置: 代码迷 >> Android >> android中相干图片的处理
  详细解决方案

android中相干图片的处理

热度:82   发布时间:2016-05-01 19:18:05.0
android中有关图片的处理

?

/**  * 按照比例放大或者缩小图片**/public static Bitmap scaleImage(Bitmap oldImage, int newW, int newH) {		return scaleImage(oldImage,newW,  newH,false);	}		public static Bitmap scaleImage(Bitmap oldImage, int newW, int newH,boolean isRecycleOld) {		if (oldImage == null)			return null;		int oldWidth = oldImage.getWidth();		int oldHeight = oldImage.getHeight();		Matrix matrix = new Matrix();		matrix.postScale((float) newW / oldWidth, (float) newH / oldHeight);		Bitmap resizedBitmap = Bitmap.createBitmap(oldImage, 0, 0, oldWidth,				oldHeight, matrix, true);				if(isRecycleOld){			oldImage.recycle();		}		return resizedBitmap;	}	
	/**	 * bitmap to byte[]	 * 	 * @param bitmap	 * @return	 */	public static byte[] flattenBitmap(Bitmap bitmap) {		if(bitmap ==null) return null;				int size = bitmap.getWidth() * bitmap.getHeight() * 4;		ByteArrayOutputStream out = new ByteArrayOutputStream(size);		try {			bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);			out.flush();			out.close();			return out.toByteArray();		} catch (IOException e) {			return null;		}	}	/**	 * byte[] to bitmap	 * 	 * @param bytes	 * @return	 */	public static Bitmap bytesToBitmap(byte[] bytes) {		if (bytes == null)			return null;		return BitmapFactory.decodeByteArray(bytes, 0, bytes.length);	}
?
  相关解决方案