android--code--从路径获取bitmap对象

public Bitmap getBitmapFromPath(String path) {

		if (!new File(path).exists()) {
			System.err.println("getBitmapFromPath: file not exists");
			return null;
		}
		// Bitmap bitmap = Bitmap.createBitmap(1366, 768, Config.ARGB_8888);
		// Canvas canvas = new Canvas(bitmap);
		// Movie movie = Movie.decodeFile(path);
		// movie.draw(canvas, 0, 0);
		//
		// return bitmap;

		byte[] buf = new byte[1024 * 1024];// 1M
		Bitmap bitmap = null;

		try {

			FileInputStream fis = new FileInputStream(path);
			int len = fis.read(buf, 0, buf.length);
			bitmap = BitmapFactory.decodeByteArray(buf, 0, len);
			if (bitmap == null) {
				System.out.println("len= " + len);
				System.err
						.println("path: " + path + "  could not be decode!!!");
			}
		} catch (Exception e) {
			e.printStackTrace();

		}

		return bitmap;
	}

你可能感兴趣的:(android-code)