JFrame v2

JFrame v2

So i recently tried to show a 6K image using my photo script and got an out of memory error lol i guess i should of seen that coming 😁 but anyways the olds scripts obviously no good but im leaving it up because bruno said it helped him do summet so hopefully it helps other people 2 its also a bit easier to read than this 1. Ive tried to fix the OOM error and i added a seekbar to the scaletype options dialog, basically how it works is the closer to 0 you set it the better the quality of the image but the more memory it will use. So my advice is to set it to the middle see how it looks and knock it up or down until you find a quality your happy with.

code is in the first post.

]]>
« (Previous Post)

2 Commentsto JFrame v2

  1. Anonymous says:

    < ![CDATA[

    bindClass(“android.widget.FrameLayout”);


    bindClass(“android.widget.ImageView”);


    bindClass(“android.graphics.BitmapFactory”);


    bindClass(“android.widget.Button”);


    bindClass(“android.widget.LinearLayout”);


    bindClass(“android.view.Gravity”);


    bindClass(“android.view.View”);


    bindClass(“android.app.AlertDialog”);


    bindClass(“android.content.DialogInterface”);


    bindClass(“android.widget.ImageView.ScaleType”);


    bindClass(“android.graphics.BitmapFactory.Options”);


    bindClass(“android.widget.SeekBar”);



    var mctx = LL.getContext();



    /*


    * Paste the path to your image between the “”


    */



    var width = item.getWidth();


    var height = item.getHeight();


    //Android.makeNewToast(“View Width:” + width +”\nView Height: ” + height, false).show();



    var path = “/storage/emulated/0/Download/6KTest.jpg”;



    var frame = new FrameLayout(mctx);


    var flp = new FrameLayout.LayoutParams(-1,-1);



    var iv = new ImageView(mctx);



    frame.addView(iv);



    var b = new Button(mctx);


    b.setBackgroundColor(0x000000);



    b.setText(“Options”); // delete value between “” to hide text


    var blp = new LinearLayout.LayoutParams(-2,-2, Gravity.BOTTOM|Gravity.RIGHT);


    b.setLayoutParams(blp);


    frame.addView(b);



    var scale = {



    center:ImageView.ScaleType.CENTER,


    centerCrop:ImageView.ScaleType.CENTER_CROP,


    centerInside:ImageView.ScaleType.CENTER_INSIDE,


    fitCenter:ImageView.ScaleType.FIT_CENTER,


    fitEnd:ImageView.ScaleType.FIT_END,


    fitStart:ImageView.ScaleType.FIT_START,


    fitXY:ImageView.ScaleType.FIT_XY,



    };



    iv.setScaleType(scale.centerCrop);



    var options = [];



    for (var keys in scale){


    options.push(keys);


    }



    b.setOnClickListener(new View.OnClickListener(){



    onClick:function(view){



    showDialog();


    }



    });



    var size = 1;



    function calculateInSampleSize(reqWidth, reqHeight) {


    var bmfo = BitmapFactory.Options();


        // Raw height and width of image


        var height = options.outHeight;


        var width = options.outWidth;


       var inSampleSize = size;



        if (height > reqHeight || width > reqWidth) {



            var halfHeight = height / 2;


            var halfWidth = width / 2;



            // Calculate the largest inSampleSize value that is a power of 2 and keeps both


            // height and width larger than the requested height and width.


            while ((halfHeight / inSampleSize) >= reqHeight


                    && (halfWidth / inSampleSize) >= reqWidth) {


                inSampleSize *= 2;


            }


        }



        return inSampleSize;


    }



    function decodeSampledBitmapFromFile(path, reqWidth, reqHeight) {



        // First decode with inJustDecodeBounds=true to check dimensions


        var bmfo = new BitmapFactory.Options();


        bmfo.inJustDecodeBounds = true;


        BitmapFactory.decodeFile(path, bmfo);



        // Calculate inSampleSize


        bmfo.inSampleSize = calculateInSampleSize(reqWidth, reqHeight);



        // Decode bitmap with inSampleSize set


        bmfo.inJustDecodeBounds = false;


        return BitmapFactory.decodeFile(path, bmfo);


    }






    function showDialog(){



    var adb = new AlertDialog.Builder(mctx);


    adb.setTitle(“Picture Options”);



    var sampleBar = new SeekBar(mctx);


    sampleBar.setProgress(size);


    sampleBar.setMax(15);


    sampleBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener(){



    onProgressChanged:function(sb, progress, fromUser){


    size = progress;


    },



    onStartTrackingTouch:function(sb){


    //Android.makeNewToast(size, false).show();


    },



    onStopTrackingTouch:function(sb){


    Android.makeNewToast(size, false).show();


    iv.setImageBitmap(decodeSampledBitmapFromFile(path, width, height));


    }




    });


    adb.setView(sampleBar);


    adb.setItems(options, new DialogInterface.OnClickListener(){



    onClick:function(dialog, which){


    switch((which +1)){



    case 1:


    iv.setScaleType(scale.center);


    break;



    case 2:


    iv.setScaleType(scale.centerCrop);


    break;



    case 3:


    iv.setScaleType(scale.centerInside);


    break;



    case 4:


    iv.setScaleType(scale.fitCenter);


    break;



    case 5:


    iv.setScaleType(scale.fitEnd);


    break;



    case 6:


    iv.setScaleType(scale.fitStart);


    break;



    case 7:


    iv.setScaleType(scale.fitXY);


    break;



    }




    }



    });



    var alert = adb.create();


    alert.show();


    }




    return frame;



    LL.save();

    ]]>

  2. Anonymous says:

    < ![CDATA[

    well this made a massive difference! 🙂

    ]]>

Leave a Reply

Your email address will not be published. Required fields are marked *