0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Unity+Android で画像保存が出来ない。

Last updated at Posted at 2020-08-24

Unity + Android で画像保存を確認しようとしたら
うまくいかなかった

外部保存には以下のものを使用
https://github.com/yasirkula/UnityNativeGallery

それでこの記事を見て解決。
どうやら、設定を何かしら変えないと保存できない模様。
細かいことは気にせず動いたので問題解決とする。
https://qiita.com/Katumadeyaruhiko/items/c2b9b4ccdfe51df4ad4a

public void SaveImage()
{
    Sprite backCameraOn = Resources.Load<Sprite>("適当な画像");
    Texture2D frontImage = createReadabeTexture2D( backCameraOn.texture );

    NativeGallery.SaveImageToGallery(
        frontImage,
        "album",
        "bodygramFront");
}

Texture2D createReadabeTexture2D(Texture2D texture2d)
{
    RenderTexture renderTexture = RenderTexture.GetTemporary(
                texture2d.width,
                texture2d.height,
                0,
                RenderTextureFormat.Default,
                RenderTextureReadWrite.Linear);

    Graphics.Blit(texture2d, renderTexture);
    RenderTexture previous = RenderTexture.active;
    RenderTexture.active = renderTexture;
    Texture2D readableTextur2D = new Texture2D(texture2d.width, texture2d.height);
    readableTextur2D.ReadPixels(new Rect(0, 0, renderTexture.width, renderTexture.height), 0, 0);
    readableTextur2D.Apply();
    RenderTexture.active = previous;
    RenderTexture.ReleaseTemporary(renderTexture);
    return readableTextur2D;
}

‘‘‘

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?