비트맵을 특정 폴더에 저장하려면 어떻게해야할까요
조회수 3625회
제가 웹서버에서 이미지를 다운받아서 그걸 화면에 출력하는 함수를 만들고 있는데요. 다운 받은 이미지를 SD카드 특정 폴더에 계속 저장할수있을까요? 그러니까 제가 하고 싶은건 다운 받은 이미지를 제가 원하는 폴더를 선택해서 저장하는 가장 간단한 방법이에요...
지금 이미지를 다운받고 화면에 비트맵을 출력하는 것까지는 했는데요. 그걸 저장하고싶은데 제가 찾은 방법은 FileOutputStream을 써서 저장하는건데 이건 byteArray가 필요한데 제가 Bitmap을 byte array로 바꾸는 방법을 몰라요...
또
MediaStore.Images.Media.insertImage(getContentResolver(), bm,
barcodeNumber + ".jpg Card Image", barcodeNumber + ".jpg Card Image");
이런 코드가있는데 이 코드는 SD카드에 잘 저장 하는데 사용자가 정한 폴더에는 저장이 안돼요. 이런 비슷한거 만들어보신분 계시나요?
1 답변
-
FileOutputStream out = null; try { out = new FileOutputStream(filename); bmp.compress(Bitmap.CompressFormat.PNG, 100, out); // bmp is your Bitmap instance // PNG is a lossless format, the compression factor (100) is ignored } catch (Exception e) { e.printStackTrace(); } finally { try { if (out != null) { out.close(); } } catch (IOException e) { e.printStackTrace(); } }
댓글 입력