User Tools

Site Tools


script_full_container_screenshot

====== About the script ====== * Purpose : The script creates a 'screenshot' of a container, but the size of the image is as big as the container and all the items are shown, even the ones out of view. * Author : [[https://plus.google.com/u/1/105066926163073195690|TrianguloY]] * Link: https://plus.google.com/u/1/105066926163073195690/posts/hb2METpC5D7 (with video) ====== How to use the script ====== This script is a tool specially designed for template/screens makers. The image is saved in png. Both the system wallpaper and the desktop wallpaper are not drawn. You can specify also to show disabled items and/or stop points. To make a screenshot just go to the container, scroll it where you want it to be, and run the script from it. The image is saved in a custom configurable path. ====== Script code ====== <sxh javascript> var path="/storage/emulated/0/LightningLauncher/Images/" var showStopPoints=false; var showInvisible=false; LL.bindClass("android.graphics.Bitmap"); LL.bindClass("java.io.FileOutputStream"); LL.bindClass("java.io.File"); //vars var c=LL.getEvent().getContainer(); var cwidth=c.getWidth(); var cheight=c.getHeight(); var box=c.getBoundingBox(); var boxleft=box.getLeft(); var boxtop=box.getTop(); var boxwidth=box.getRight()-boxleft; var boxheight=box.getBottom()-boxtop; var image=LL.createImage(boxwidth,boxheight); var canvas=image.draw(); //current position var pos=[c.getPositionX(),c.getPositionY(),c.getPositionScale()]; var name=prompt("This will create a screenshot of this container. Please wait until 'Done' shows. \n\n Which name do you want the picture to have?","container"+c.getId()); if(name==null)return; //draw the container background if any var background=c.getView().getBackground(); if(background!=null)canvas.draw(background,pos[0],pos[1],null); //draw each item var items=c.getItems(); for(var t=0;t<items.getLength();++t){ var it=items.getAt(t); var ittype=it.getType(); if( (ittype=="StopPoint"&&!showStopPoints) || (!it.isVisible()&&!showInvisible) ) continue; //get image var itimage=getBitmap(it.getRootView()); //position var posx=it.getPositionX(); var posy=it.getPositionY(); //due to pinned mode, the real position is a bit different var itpinmode=it.getProperties().getString("i.pinMode"); if(itpinmode!="NONE"){ posx=posx/pos[2]; posy=posy/pos[2]; //resize bitmap itimage=resize(itimage,1/pos[2]); //modify position if(itpinmode.indexOf("X")!=-1) posx+=pos[0]; if(itpinmode.indexOf("Y")!=-1) posy+=pos[1]; }//end pinmode //draw in the master bitmap posx-=boxleft; posy-=boxtop; if(ittype=="StopPoint"){ posx-=it.getWidth()/2; posy-=it.getHeight()/2; } canvas.drawBitmap(itimage,posx,posy,null); }//end for // have the object build the directory structure, if needed. var dir=new File(path); dir.mkdirs(); //save to file image.update(); image.save(); image.getBitmap().compress(Bitmap.CompressFormat.PNG,100,new FileOutputStream(path+name+".png")); Android.makeNewToast("Done", true).show(); //get the bitmap to copy it in the full image function getBitmap(view) { //Define a bitmap with the same size as the view var returnedBitmap = LL.createImage(view.getWidth(),view.getHeight()); //Bind a canvas to it var canvas = returnedBitmap.draw(); //Get the view's background var bgDrawable =view.getBackground(); if (bgDrawable!=null) //has background drawable, then draw it on the canvas bgDrawable.draw(canvas); // draw the view on the canvas view.draw(canvas); //return the bitmap returnedBitmap.update(); returnedBitmap.save(); return returnedBitmap.getBitmap(); } function resize(bitmap,scale){ return Bitmap.createScaledBitmap(bitmap,bitmap.getWidth()*scale,bitmap.getHeight()*scale,false); } </sxh>

script_full_container_screenshot.txt · Last modified: 2015/08/16 15:46 by trianguloy