'convert'에 해당되는 글 1건

  1. 안드로이드 개발 - 비트맵을 파일로 변환하기(Bitmap to file)

안드로이드에서 Bitmap을 Sdcard 같은 저장장치에 파일로 저장할 필요성이 있을 때가 있습니다.

간단한 함수로 파일로 저장이 가능합니다.


안드로이드 개발 - 비트맵을 파일로 변환하기(Bitmap to file)


1. 아래와 같은 함수를 등록해줍니다.


 
// Bitmap to File
	public  void SaveBitmapToFileCache(Bitmap bitmap, String strFilePath,
			String filename) {

		File file = new File(strFilePath);

		// If no folders
		if (!file.exists()) {
			file.mkdirs();
			// Toast.makeText(this, "Success", Toast.LENGTH_SHORT).show();
		}

		File fileCacheItem = new File(strFilePath + filename);
		OutputStream out = null;

		try {
			fileCacheItem.createNewFile();
			out = new FileOutputStream(fileCacheItem);

			bitmap.compress(CompressFormat.JPEG, 100, out);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				out.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}



2. 함수를 호출할 때에는 아래와 같이 호출합니다.(bitmap에는 비트맵, strFilePath에는 파일 경로, filename에는 파일 이름으로 사용할할 문자열을 지정해주면 됩니다.


SaveFileToFileCache(bitmap, strFilePath, filename);






도움이 되셨나요?

그럼 손가락을 눌러주세요:)