Create extension like this

component_method

ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.yourimage); 
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos); 
byte[] imageBytes = baos.toByteArray(); 
String imageString = Base64.encodeToString(imageBytes, Base64.DEFAULT);

i want make this extension like piture , i dont know how to do in kodular

Try…

import java.io.ByteArrayOutputStream;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.util.Base64;
import android.graphics.BitmapFactory;

And:

    @SimpleFunction(description = "Encodes the image from the given absolute path to a base 64 string.")
    public String EncodeImage(String path){
        ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
        Bitmap bitmap = BitmapFactory.decodeFile(path); 
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos); 
        byte[] imageBytes = baos.toByteArray(); 
        String imageString = Base64.encodeToString(imageBytes, Base64.DEFAULT);
        return imageString;
    }
1 Like

succes thank for teach me :smiling_face_with_three_hearts:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.