Skip to content

Commit 7ddb583

Browse files
author
Stephen Hodgson
committed
Correctly crops icons when generating them
1 parent c4649de commit 7ddb583

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

Assets/HoloToolkit/Utilities/Scripts/Editor/SetIconsWindow.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,13 +272,19 @@ private static string CloneAndResizeToFile(PlayerSettings.WSAImageType type, Pla
272272

273273
// Resize clone to desired size
274274
TextureScale.Bilinear(clone, (int)iconSize.x, (int)iconSize.y);
275-
clone.Compress(true);
276-
AssetDatabase.SaveAssets();
277275

278-
if (clone.GetRawTextureData().Length > 204800)
276+
// Crop
277+
Color[] pix = clone.GetPixels(0, 0, (int)iconSize.x, (int)iconSize.y);
278+
clone = new Texture2D((int)iconSize.x, (int)iconSize.y, TextureFormat.ARGB32, false);
279+
clone.SetPixels(pix);
280+
clone.Apply();
281+
282+
var rawData = clone.EncodeToPNG();
283+
File.WriteAllBytes(filePath, rawData);
284+
285+
if (rawData.Length > 204800)
279286
{
280287
Debug.LogWarningFormat("{0} exceeds the minimum file size of 204,800 bytes, please use a smaller image for generating your icons.", clone.name);
281-
return string.Empty;
282288
}
283289
}
284290
catch (Exception e)

Assets/HoloToolkit/Utilities/Scripts/Editor/TextureScale.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
3+
// See http://wiki.unity3d.com/index.php/TextureScale
34

45
using System.Threading;
56
using UnityEngine;
@@ -107,7 +108,7 @@ private static void ThreadedScale(Texture2D tex, int newWidth, int newHeight, bo
107108
}
108109
}
109110

110-
tex.Resize(newWidth, newHeight, TextureFormat.RGB24, false);
111+
tex.Resize(newWidth, newHeight, TextureFormat.ARGB32, false);
111112
tex.SetPixels(newColors);
112113
tex.Apply();
113114

0 commit comments

Comments
 (0)