Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[MenuItem("Window/TakeScreenshotWithCaptureScreenshotAsTexture")]
public static void Menu()
{
var tex = ScreenCapture.CaptureScreenshotAsTexture();
var jpgBytes = tex.EncodeToJPG(10);// 90KB
using (var sw = new StreamWriter("a.jpg"))
{
sw.BaseStream.Write(jpgBytes, 0, jpgBytes.Length);
}
}
@sassembla

This comment has been minimized.

Copy link
Owner Author

@sassembla sassembla commented Jun 3, 2019

↑のコードをUnity Editorで実行してみてください(メニュー > Window > TakeScreenshotWithCaptureScreenshotAsTexture で実行できる)

んでプロジェクトフォルダに生成されたa.jpgを、Unityのバージョンと一緒にgistに書き込んでもらえると大変うれしい。

果たして正しく撮影できるUnity versionが存在するのか?

@sassembla

This comment has been minimized.

Copy link
Owner Author

@sassembla sassembla commented Jun 3, 2019

NotValid

  • Mac 2017.4.22
  • Mac 2017.4.27
  • Mac 2018.2.2f1
  • Mac 2018.3.0f2(crash)
  • Win 2018.3.6f1(crash)
  • Mac 2018.3.11
  • Mac 2019.1.1f1(crash)
  • Mac 2019.1.0f2

Valid

  • Win 2019.1.0f2
@makoto-unity

This comment has been minimized.

Copy link

@makoto-unity makoto-unity commented Jun 4, 2019

Mac でエディタごと落ちた。

  • 2019.1.1f1
  • 2018.3.0f2
@makoto-unity

This comment has been minimized.

Copy link

@makoto-unity makoto-unity commented Jun 4, 2019

Windows でも落ちた。

  • 2018.3.6f1

エディタでそもそも読んではいけない系?

@torikizi

This comment has been minimized.

Copy link

@torikizi torikizi commented Jun 4, 2019

「Ignoring depth surface load action as it is memoryless」の警告あり

  • 2019.1.0f2 mac

D8NaiEeUwAACkik

@sassembla

This comment has been minimized.

Copy link
Owner Author

@sassembla sassembla commented Jun 4, 2019

エディタでそもそも読んではいけない系?

ScreenCapture.CaptureScreenshot はEditorで読んでも動くんで、AsTextureだけちゃんと動かないのはバグではという感想っす。
@makoto-unity

@torikizi

This comment has been minimized.

Copy link

@torikizi torikizi commented Jun 4, 2019

警告なし
2019.1.0f2 windows

am

@sassembla

This comment has been minimized.

Copy link
Owner Author

@sassembla sassembla commented Jun 4, 2019

Finally! you've got a perfect result! isn't it?

@torikizi

This comment has been minimized.

Copy link

@torikizi torikizi commented Jun 4, 2019

take2
警告なし
2019.1.0f2 windows

caps

@sassembla

This comment has been minimized.

Copy link
Owner Author

@sassembla sassembla commented Jun 4, 2019

take2
警告なし
2019.1.0f2 windows

caps

Perfect! 素晴らしい。

@ishtaka

This comment has been minimized.

Copy link

@ishtaka ishtaka commented Jun 4, 2019

Mac 2018.2.2f1
エラー、警告なしでしたが

a
スクリーンショット 2019-06-04 23 51 56

@sassembla

This comment has been minimized.

Copy link
Owner Author

@sassembla sassembla commented Jun 8, 2019

conclusion:

Unity Editor 2019.1.0f2 windows can take valid screenshot on Editor without playing.

Unity Editor 2019.1.2f1 mac also can take valid screenshot onEditor with playing.

@sassembla

This comment has been minimized.

Copy link
Owner Author

@sassembla sassembla commented Jun 9, 2019

Mac 2018.2.2f1
エラー、警告なしでしたが

a
スクリーンショット 2019-06-04 23 51 56

Thank you!

@sassembla

This comment has been minimized.

Copy link
Owner Author

@sassembla sassembla commented Jun 25, 2019

limited: free aspect mode required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment