Platform/Android

[Asset] asset에서 읽은 이미지 base64 인코딩 된 이미지로

개랭갱깽스타 2020. 8. 6. 10:09

asset에서 읽은 이미지 base64 인코딩 된 이미지로

 

private HashMap<String, HashMap<String, String>> createInstallManagerInfo() throws Exception {
        HashMap<String, HashMap<String, String>> installHashMap = new HashMap<>();

        //asset에서 읽은 이미지 -> bas64 인코딩된 이미지로
        AssetManager assetManager = getResources().getAssets();
        InputStream is = null;
        is = assetManager.open("seal.jpg");

        byte[] buf = new byte[1024];
        int bytesRead;
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        while ((bytesRead = is.read(buf)) != -1) {
            output.write(buf, 0, bytesRead);
        }
        byte[] fileArray = output.toByteArray();

        String base64EncData = Base64.encodeToString(fileArray, Base64.DEFAULT);
        Bitmap bitmap = BitmapFactory.decodeByteArray(fileArray, 0, fileArray.length);

        HashMap<String, String> imageHashMap = new HashMap<>();
        imageHashMap.put("p_bsMgNm", base64EncData);

        installHashMap.put("30010001", imageHashMap);
        return installHashMap;
    }

 

 

참고

https://stackoverflow.com/questions/36198637/convert-assets-image-png-to-byte

 

Convert /assets/image.png to byte[]

How to convert /assets/image.png to byte[] ? I've tried like that (based on solution found on SO): public void printimage(View view) { AssetManager assetManager = getAssets(); InputStream

stackoverflow.com

 

반응형

'Platform > Android' 카테고리의 다른 글

[Error] [SQLITE_ERROR] SQL error or missing database  (0) 2020.08.12
[debug]  (0) 2020.08.06
아키텍처  (0) 2020.07.31
[INTENT] URL 로 Activity 호출  (0) 2020.07.23
[enum, Retrofit]  (0) 2020.07.20