Image Editor

Register Image Edit Contract

To use the image module, you first need to work with the TruvideoSdkImageEditContract by using registerForActivityResult, which takes TruvideoSdkImageEditContract and a callback that returns the result as a String.

To use the image module, you first need to work with the TruvideoSdkImageEditContract by using registerForActivityResult, which takes TruvideoSdkImageEditContract and a callback that returns the result as a String.

import androidx.activity.result.ActivityResultLauncher;
import androidx.appcompat.app.AppCompatActivity;
import com.truvideo.sdk.image.ui.edit.activities.edit.TruvideoSdkImageEditContract;
import com.truvideo.sdk.image.ui.edit.activities.edit.TruvideoSdkImageEditParams;

public class YourActivity extends AppCompatActivity{
    ActivityResultLauncher<TruvideoSdkImageEditParams> launcher;
    @Override 
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // initiate imageLauncher 
        launcher = registerForActivityResult(
            new TruvideoSdkImageEditContract()
            , result -> {
            // handle result
        });
        //...rest of your code
    }
}

Launching the Image Editing Activity

Launches the image editing activity using the previously registered ActivityResultLauncher.

Parameters:

  • TruvideoSdkImageEditParams: This object encapsulates the parameters needed for the image editing activity. Specifically, it includes:

    • path: The file path of the image to be edited.

    • outputPath: The file path where the edited image will be saved after the editing process is completed.

Note

The ActivityResultLauncher should be registered in a lifecycle-aware manner, typically in onCreate or onAttach, to avoid memory leaks or crashes.

//path: actual iamge path 
public static void editImage(Context context, String path){
        // get output path for storing new image
        String outputPath = context.getFilesDir().getPath()+System.currentTimeMillis()+".png";
        launcher.launch(new TruvideoSdkImageEditParams(path,outputPath));
}

Last updated

Was this helpful?