full container screenshot utility
full container screenshot utility
This script is a tool specially designed for template/screens makers.
It 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. 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.
If you have any suggestion I’ll try to implement if possible.
]]>
< ![CDATA[
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
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);
}
]]>
< ![CDATA[
I had trouble initially because of line 1, the directory part didn’t exist on my device. To fix this just edit that part of the script to the desired directory.
And 2. It would be cool to at least write the desktop wallpaper just in case there’s an error or something. It would also serve a purpose when showing off the artwork.
It’s a cool way to take screenshots without having to actually take a screenshot. I like it.
]]>
< ![CDATA[
That is amazing
]]>
< ![CDATA[
Why didn’t you use view.draw(canvas) ?
Wouldn’t that simpifiy the code a lot?
]]>
< ![CDATA[
Lukas Morawietz I’m using that.
If your question is why I’m not using that directly on the container, the answer is that I want to draw all the container, not only the displayed part.
]]>
< ![CDATA[
TrianguloY
I see… zooming out is not a solution becuase of pinned items. I thought the draw method would draw the whole container.
]]>
< ![CDATA[
In fact, if you noticed the script has a V2.0 name. This is because the first one I made was drawing the full picture moving the container and using what you said. At the end it was easier to draw the items one by one
]]>