SaveImage

Save Image

Often you want to save image and then share it on social networks or just save it to gallery. Until we haven't added this feature in to the master branch here is a workaround.

Build result image

As you know Paintcraft has several layers - background and outline. so first what you need to do is combine those layers together in to the one image.

In to CanvasController.cs class add following code

public Texture2D GetSavedImage()
{
RenderTexture tempRT = RenderTexture.GetTemporary(BackLayerController.RenderTexture.width,
BackLayerController.RenderTexture.height);
Graphics.Blit(BackLayerController.RenderTexture, tempRT);
Graphics.Blit(OutlineTexture, tempRT, OutlineMaterial);
RenderTexture activeRT = RenderTexture.active;
RenderTexture.active = tempRT;
TmpTexture2D.ReadPixels(new Rect(0,0,BackLayerController.RenderTexture.width, BackLayerController.RenderTexture.height),0,0,false );
RenderTexture.active = activeRT;
RenderTexture.ReleaseTemporary(tempRT);
return TmpTexture2D;
}

Now you can use this code to fetch result image which contains both bg and outline layers

Share Image

To share image most easiest way is to use this free plugin UnityNativeSharing

It has very simple api and usually what you need to do is just to write texture2d to the filesystem and then call this

NativeShare.Share(text, imagePath, "", "", "image/png", true, "");