ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [Android] How to get image file from assets & set bitmap to canvas.
    Frontend/android 2021. 2. 5. 16:22

     

     

     

     

     

    
    Bitmap assetsRead(String file) {
            InputStream is;
            Bitmap bitmap = Bitmap.createBitmap(previewWidth, previewHeight, Config.ARGB_8888);
    
            try {
                is = getAssets().open(file);
                int size = is.available();
                byte[] buffer = new byte[size];
                is.read(buffer);
                is.close();
                bitmap = BitmapFactory.decodeByteArray( buffer, 0, buffer.length ) ;
                bitmap = Bitmap.createScaledBitmap(bitmap, 720, 720, false);
            } catch (IOException e) {
                e.printStackTrace();
            }
    
            return bitmap ;
        }
    
    int width = canvas.getWidth();
    int height = canvas.getHeight() / 2;
    Bitmap resize_bitmap = Bitmap.createScaledBitmap(assetsRead("image.png"), width, height, false);
    
    canvas.drawBitmap(resize_bitmap, 0, 0, null);

     

    댓글

Designed by Tistory.