Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

スクリーンショット作成時に、JpegEncodeしているのに拡張子がpng #646

Merged
merged 1 commit into from
Jan 4, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions Assets/VRM/Editor/Meta/VRMMetaObjectEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public override void OnInspectorGUI()

void TakeScreenShot()
{
var dst = SaveDialog(m_target, "png");
var dst = SaveDialog(m_target, "png", "jpg");
if (string.IsNullOrEmpty(dst))
{
return;
Expand All @@ -251,7 +251,19 @@ void TakeScreenShot()
Camera.main.Render();
tex.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0);
tex.Apply();
File.WriteAllBytes(dst, tex.EncodeToJPG());

var ext = Path.GetExtension(dst).ToLower();
switch (ext)
{
case ".png":
File.WriteAllBytes(dst, tex.EncodeToPNG());
break;

case ".jpg":
File.WriteAllBytes(dst, tex.EncodeToJPG());
break;
}

var assetPath = MeshUtility.UnityPath.FromFullpath(dst);
EditorApplication.delayCall += () =>
{
Expand All @@ -268,7 +280,7 @@ void TakeScreenShot()
}
}

static string SaveDialog(VRMMetaObject meta, string ext)
static string SaveDialog(VRMMetaObject meta, params string[] ext)
{
var directory = Application.dataPath;
var assetPath = AssetDatabase.GetAssetPath(meta);
Expand All @@ -279,8 +291,8 @@ static string SaveDialog(VRMMetaObject meta, string ext)
return EditorUtility.SaveFilePanel(
"Save thumbnail",
directory,
$"thumbnail.{ext}",
ext);
$"thumbnail.{ext[0]}",
string.Join(",", ext));
}

static (Rect, Rect) FixedRight(Rect r, int width)
Expand Down