Code example for BitmapFactory.Options

Methods: decodeFiledecodeStream

0
 
	public static final int UNCONSTRAINED = -1;
 
	// ���������Ϣ 
	public static Options getOptions(String path) {
		Options options = new Options();
		// ֻ��ߣ�����ȡ��� 
		options.inJustDecodeBounds = true;
		// ���ص��ڴ� 
		BitmapFactory.decodeFile(path, options);
		return options;
	} 
 
	// ���ͼ�� 
	private static Bitmap getBitmapByPath(String path, Options options,
			int screenWidth, int screenHeight)  {
		 
		 
		File file = new File(path);
		if (!file.exists()) {
			return null; 
		} 
		FileInputStream inputStream = null;
		try { 
			inputStream = new FileInputStream(file);
		} catch (FileNotFoundException e1) {
			e1.printStackTrace();
		} 
		if (options != null) {
			Rect r = getScreenRegion(screenWidth, screenHeight);
			// ȡ��ͼƬ�Ŀ�͸� 
			int w = r.width();
			int h = r.height();
			int maxSize = w > h ? w : h;
			// �������ű��� 
			int inSimpleSize = computeSampleSize(options, maxSize, w * h);
			// �������ű��� 
			options.inPreferredConfig = Bitmap.Config.RGB_565;
			options.inSampleSize = inSimpleSize;
			options.inJustDecodeBounds = false;
		} 
 
		// ����ѹ�����ͼƬ 
		Bitmap bitmap = BitmapFactory.decodeStream(inputStream, null, options);
		try { 
			inputStream.close();
		} catch (IOException e) {
			e.printStackTrace();
		}