[안드로이드] svg path 따라 잘린 bitmap만들기 그리고 이미지뷰에 붙이기

용씨·2021년 8월 21일
0

[공경진] fillin-map

목록 보기
6/9

svg path 따라 잘린 bitmap만들기

이미지 절대 경로 구하기

갤러리에서 선택한 이미지의 절대 경로를 일단 구한다.
이미지 uri를 매개변수로 둔다.

// 이미지 uri를 절대 경로로 바꾸기
    private fun createCopyAndReturnRealPath(uri: Uri): String? {
        val context = requireActivity().applicationContext
        val contentResolver = context.contentResolver ?: return null
        // Create file path inside app's data dir
        val filePath =
            (context.applicationInfo.dataDir + File.separator + System.currentTimeMillis())
        val file = File(filePath)
        try {
            val inputStream = contentResolver.openInputStream(uri) ?: return null
            val outputStream: OutputStream = FileOutputStream(file)
            val buf = ByteArray(1024)
            var len: Int
            while (inputStream.read(buf).also { len = it } > 0) outputStream.write(buf, 0, len)
            outputStream.close()
            inputStream.close()
        } catch (e: IOException) {
            e.printStackTrace()
        }
        val path = file.absolutePath

        return path
    }

그 다음은 https://github.com/tarek360/Bitmap-Cropping 를 참고

그리고 이미지뷰에 붙이기

imageView.setImageBitmap(convertToMap(srcBitmap))
profile
아침형 인간이 목표

0개의 댓글