unity3d - Take photo in unity c# -


i'm trying build program takes photo , places different background, monument or so. far, able turn camera on when start project code

 webcamtexture = new webcamtexture();  rawimage.texture = webcamtexture;  rawimage.material.maintexture = webcamtexture;  webcamtexture.play();  texture2d phototaken = new texture2d (webcamtexture.width, webcamtexture.height);  phototaken.setpixels (webcamtexture.getpixels ());  phototaken.apply (); 

however, can't take screenshot or photo because ends black. i've tried different codes nothing working. can please help? thanks

edit

after tries, code have:

webcamtexture webcamtexture; public rawimage rawimage;   void start () {     webcamtexture = new webcamtexture();     rawimage.texture = webcamtexture;     rawimage.material.maintexture = webcamtexture;     webcamtexture.play();      rendertexture texture= new rendertexture(webcamtexture.width, webcamtexture.height,0);      graphics.blit(webcamtexture, texture);      button btn = yourbutton.getcomponent<button>();     btn.onclick.addlistener(onclick);  }  public ienumerator coroutine(){      yield return new waitforendofframe (); }  public void onclick() {      var width = 767;     var height = 575;      texture2d texture = new texture2d(width, height);     texture.readpixels(new rect(0, 0, width, height), 0, 0);     texture.apply();      // encode texture png     var bytes = texture.encodetopng();     //destroy(texture);       file.writeallbytes (application.datapath + "/../savedscreen.png", bytes);      } 

and next code screenshot taken, takes photo of whole thing, , not bit of screen.

void start() {     // set playback framerate!     // (real time doesn't influence time anymore)     time.captureframerate = framerate;      // find folder doesn't exist yet appending numbers!     realfolder = folder;     int count = 1;     while (system.io.directory.exists(realfolder))     {         realfolder = folder + count;         count++;     }     // create folder     system.io.directory.createdirectory(realfolder); }  void update() {     // name "realfolder/shot 0005.png"     var name = string.format("{0}/shot {1:d04}.png", realfolder, time.framecount);      // capture screenshot     application.capturescreenshot(name, sizemultiplier); } 

}

you can take screenshot in unity

    application.capturescreenshot("screenshot.png"); 

reference

edit 1
take screenshot on specific part of screen use following script:

 var width = 400;  var height = 300;  var startx = 200;  var starty = 100;  var tex = new texture2d (width, height, textureformat.rgb24, false);   tex.readpixels (rect(startx, starty, width, height), 0, 0);  tex.apply ();   // encode texture png  var bytes = tex.encodetopng();  destroy(tex);   file.writeallbytes(application.datapath + "/../savedscreen.png", bytes); 

reference


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -