[Help] Loading image to replace camera buffer

179 posts
Thanks Meter: 151
By esun, Senior Member on 13th September 2015, 04:37 PM
Post Reply Email Thread
So I've created module to hijack an app's onPictureTaken callback method to manipulate the image-data that is returned from the Camera (android.hardware.Camera.PictureCallback).

I have succeeded to manipulate the image to return a Grayscale of it which was my first goal.

Now I want to replace the entire image with an image loaded from the filesystem which I'm unsuccessful in doing. I've tried different methods, paths etc. but haven't managed to do it. I've never been able to find the file which I want to load.

The full path of the image file I want to load is according to Solid Explorer
What code should I use to load the filesystem image into a Bitmap?
Do I need to take any extra Camera parameters into account that says stuff about the image?
Do I need take file permissions into account?

I'm running an OPO on Lollipop 5.0.2 / Cyanogen OS 12.0 / Xposed 67

This is the code I've used to create the Grayscale example:
import android.os.Environment;
import static;
public class CamHook implements IXposedHookLoadPackage {
    public void handleLoadPackage(final LoadPackageParam lpparam) throws Throwable {
        XposedBridge.log("Loaded app: " + lpparam.packageName);
        if (!lpparam.packageName.equals(""))
        XposedBridge.log("CamHook: We're here!");
        findAndHookMethod("$3$1", lpparam.classLoader, "onPictureTaken", "byte[]", "android.hardware.Camera", new XC_MethodHook() {
            protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                XposedBridge.log("CamHook: before picture taken");
                XposedBridge.log("CamHook: byteLength " + ((byte[]) (param.args)[0]).length);
                byte[] bitmapdata = ((byte[]) (param.args)[0]);
                Bitmap bitmap = BitmapFactory.decodeByteArray(bitmapdata, 0, bitmapdata.length);
                XposedBridge.log("CamHook: StorageState: " + Environment.getExternalStorageState());
                XposedBridge.log("CamHook: StoragePath: " + Environment.getExternalStorageDirectory().getAbsolutePath());
                XposedBridge.log("CamHook: StoragePathEnv: " + System.getenv("EXTERNAL_STORAGE"));
                //Bitmap bitmap = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory().getAbsolutePath() + "/input.jpg");
                XposedBridge.log("CamHook: Bitmap is null: " + (bitmap == null));
                bitmap = toGrayscale(bitmap);
                ByteArrayOutputStream blob = new ByteArrayOutputStream();
                bitmap.compress(Bitmap.CompressFormat.JPEG, 0, blob);
                param.args[0] = blob.toByteArray();
            protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                // this will be called after the clock was updated by the original method
    public Bitmap toGrayscale(Bitmap bmpOriginal)
        int width, height;
        height = bmpOriginal.getHeight();
        width = bmpOriginal.getWidth();
        Bitmap bmpGrayscale = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        Canvas c = new Canvas(bmpGrayscale);
        Paint paint = new Paint();
        ColorMatrix cm = new ColorMatrix();
        ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm);
        c.drawBitmap(bmpOriginal, 0, 0, paint);
        return bmpGrayscale;
18th September 2015, 03:44 AM |#2  
Account currently disabled
Thanks Meter: 0
Does this mean it's working? App settings and YouTube adaway seem to work. But I know app settings can work without xposed
Attached Thumbnails
Click image for larger version

Name:	1442544198690.jpg
Views:	428
Size:	68.9 KB
ID:	3477577  
4th January 2018, 03:47 PM |#3  
Junior Member
Thanks Meter: 0
Did you get this to work?

I found your thread. Did you ever get this to work?

Kind regards!
14th July 2019, 08:55 AM |#4  
Junior Member
Thanks Meter: 0
Hello did it work out for you? I am also looking into similar thing.
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes