public static bool ExportImage(UPAImage img, TextureType type, TextureExtension extension) { string path = EditorUtility.SaveFilePanel( "Export image as " + extension.ToString(), "Assets/", img.name + "." + extension.ToString().ToLower(), extension.ToString().ToLower()); if (path.Length == 0) return false; byte[] bytes; if (extension == TextureExtension.PNG) { // Encode texture into PNG bytes = img.GetFinalImage(true).EncodeToPNG(); } else { // Encode texture into JPG #if UNITY_4_2 bytes = img.GetFinalImage(true).EncodeToPNG(); #elif UNITY_4_3 bytes = img.GetFinalImage(true).EncodeToPNG(); #elif UNITY_4_5 bytes = img.GetFinalImage(true).EncodeToJPG(); #else bytes = img.GetFinalImage(true).EncodeToJPG(); #endif } path = FileUtil.GetProjectRelativePath(path); //Write to a file in the project folder File.WriteAllBytes(path, bytes); AssetDatabase.Refresh(); TextureImporter texImp = AssetImporter.GetAtPath(path) as TextureImporter; if (type == TextureType.texture) texImp.textureType = TextureImporterType.Image; else if (type == TextureType.sprite) { texImp.textureType = TextureImporterType.Sprite; #if UNITY_4_2 texImp.spritePixelsToUnits = 10; #elif UNITY_4_3 texImp.spritePixelsToUnits = 10; #elif UNITY_4_5 texImp.spritePixelsToUnits = 10; #else texImp.spritePixelsPerUnit = 10; #endif } texImp.filterMode = FilterMode.Point; texImp.textureFormat = TextureImporterFormat.AutomaticTruecolor; AssetDatabase.ImportAsset(path); return true; }
public ApplicationContext( UndoRedoManager undoRedoManager, Channels channels, TextureResolution textureResolution, ImmutableTextureResolution chunkResolution, string cacheDirectory, TextureExtension cacheTextureExtension) { Assert.ArgumentNotNull(undoRedoManager, nameof(undoRedoManager)); Assert.ArgumentNotNull(channels, nameof(channels)); Assert.ArgumentNotNull(textureResolution, nameof(textureResolution)); Assert.ArgumentNotNull(chunkResolution, nameof(chunkResolution)); Assert.ArgumentNotNullOrEmptry(cacheDirectory, nameof(cacheDirectory)); UndoRedoManager = undoRedoManager; Channels = channels; TextureResolution = textureResolution; CacheDirectory = cacheDirectory; ResourcesCacheDirectory = Path.Combine(CacheDirectory, "Resources"); CacheTextureResolution = cacheTextureExtension; CacheTextureResolutionString = CacheTextureResolution.ToString(); initialChunkResolution = new ImmutableTextureResolution(chunkResolution.AsEnum); CalculateChunkProperties(); Channels.Changed += (s, e) => NotifyChanged(); TextureResolution.Changed += (s, e) => { CalculateChunkProperties(); NotifyChanged(); }; }
public override bool Write(GH_IWriter writer) { writer.SetString("Image", ImageFile); writer.SetString("ImTexInterpolation", Interpolation.ToString()); writer.SetString("ImTexColorSpace", ColorSpace.ToString()); writer.SetString("ImTexTextureExtension", TextureExtension.ToString()); writer.SetString("ImTexProjection", Projection.ToString()); return(base.Write(writer)); }
public ResourceMetadata(ApplicationContext context, string name, Guid guid, TextureExtension textureExtension, ResourceType resourceType) { Assert.ArgumentNotNull(context, nameof(context)); Assert.ArgumentNotNullOrEmptry(name, nameof(name)); Name = name; Guid = guid; TextureExtension = textureExtension; ResourceType = resourceType; Context = context; ResourceCacheDirectory = Path.Combine(context.ResourcesCacheDirectory, name + "_" + guid.ToString()); TextureExtensionString = textureExtension.ToString(); }
public static bool ExportImage(UPAImage img, TextureType type, TextureExtension extension) { string path = EditorUtility.SaveFilePanel( "Export image as " + extension.ToString(), "Assets/", img.name + "." + extension.ToString().ToLower(), extension.ToString().ToLower()); if (path.Length == 0) { return(false); } byte[] bytes; if (extension == TextureExtension.PNG) { // Encode texture into PNG bytes = img.GetFinalImage(true).EncodeToPNG(); } else { // Encode texture into JPG #if UNITY_4_2 bytes = img.GetFinalImage(true).EncodeToPNG(); #elif UNITY_4_3 bytes = img.GetFinalImage(true).EncodeToPNG(); #elif UNITY_4_5 bytes = img.GetFinalImage(true).EncodeToJPG(); #else bytes = img.GetFinalImage(true).EncodeToJPG(); #endif } path = FileUtil.GetProjectRelativePath(path); //Write to a file in the project folder File.WriteAllBytes(path, bytes); AssetDatabase.Refresh(); TextureImporter texImp = AssetImporter.GetAtPath(path) as TextureImporter; if (type == TextureType.texture) { texImp.textureType = TextureImporterType.Default; } else if (type == TextureType.sprite) { texImp.textureType = TextureImporterType.Sprite; #if UNITY_4_2 texImp.spritePixelsToUnits = 10; #elif UNITY_4_3 texImp.spritePixelsToUnits = 10; #elif UNITY_4_5 texImp.spritePixelsToUnits = 10; #else texImp.spritePixelsPerUnit = 10; #endif } texImp.filterMode = FilterMode.Point; texImp.textureFormat = TextureImporterFormat.AutomaticTruecolor; AssetDatabase.ImportAsset(path); return(true); }
public static string TextureExtensionToStringR(TextureExtension d) => d.ToString().Replace("_", " ");
public static bool ExportImage(UPAImage img, TextureType type, TextureExtension extension) { var folder = "Assets/"; var fileName = img.name + "." + extension.ToString().ToLower(); if (PlayerPrefs.HasKey("pixelfile")) { folder = PlayerPrefs.GetString("pixelfolder"); fileName = PlayerPrefs.GetString("pixelfile"); } string path = EditorUtility.SaveFilePanel( "Export image as " + extension.ToString(), folder, fileName, extension.ToString().ToLower()); if (path.Length == 0) { return(false); } byte[] bytes; if (extension == TextureExtension.PNG) { // Encode texture into PNG bytes = img.GetFinalImage(true).EncodeToPNG(); } else { // Encode texture into JPG #if UNITY_4_2 bytes = img.GetFinalImage(true).EncodeToPNG(); #elif UNITY_4_3 bytes = img.GetFinalImage(true).EncodeToPNG(); #elif UNITY_4_5 bytes = img.GetFinalImage(true).EncodeToJPG(); #else bytes = img.GetFinalImage(true).EncodeToJPG(); #endif } path = FileUtil.GetProjectRelativePath(path); PlayerPrefs.SetString("pixeldir", Path.GetDirectoryName(path)); PlayerPrefs.SetString("pixelfile", Path.GetFileName(path)); PlayerPrefs.Save(); //Write to a file in the project folder File.WriteAllBytes(path, bytes); AssetDatabase.Refresh(); TextureImporter texImp = AssetImporter.GetAtPath(path) as TextureImporter; if (type == TextureType.texture) { texImp.textureType = TextureImporterType.Default; } else if (type == TextureType.sprite) { texImp.textureType = TextureImporterType.Sprite; #if UNITY_4_2 texImp.spritePixelsToUnits = 10; #elif UNITY_4_3 texImp.spritePixelsToUnits = 10; #elif UNITY_4_5 texImp.spritePixelsToUnits = 10; #else texImp.spritePixelsPerUnit = 32; #endif } texImp.filterMode = FilterMode.Point; texImp.textureCompression = TextureImporterCompression.Uncompressed; AssetDatabase.ImportAsset(path); return(true); }
public static bool ExportImage(UPAImage img, TextureType type, TextureExtension extension) { string path = EditorUtility.SaveFilePanel( "Export image as " + extension.ToString(), "Assets/", img.name + "." + extension.ToString(), extension.ToString()); if (path.Length == 0) { return(false); } Texture2D tex = new Texture2D(img.width, img.height, TextureFormat.RGBA32, false); for (int x = 0; x < img.width; x++) { for (int y = 0; y < img.height; y++) { tex.SetPixel(x, img.height - y - 1, img.map[x + y * img.width].color); } } tex.Apply(); byte[] bytes; if (extension == TextureExtension.PNG) { // Encode texture into PNG bytes = tex.EncodeToPNG(); } else { // Encode texture into JPG #if UNITY_4_2 bytes = tex.EncodeToPNG(); #elif UNITY_4_3 bytes = tex.EncodeToPNG(); #elif UNITY_4_5 bytes = tex.EncodeToJPG(); #else bytes = tex.EncodeToJPG(); #endif } GameObject.DestroyImmediate(tex); path = FileUtil.GetProjectRelativePath(path); //Write to a file in the project folder File.WriteAllBytes(path, bytes); AssetDatabase.Refresh(); TextureImporter texImp = AssetImporter.GetAtPath(path) as TextureImporter; if (type == TextureType.texture) { texImp.textureType = TextureImporterType.Image; } else if (type == TextureType.sprite) { texImp.textureType = TextureImporterType.Sprite; #if UNITY_4_2 texImp.spritePixelsToUnits = 10; #elif UNITY_4_3 texImp.spritePixelsToUnits = 10; #elif UNITY_4_5 texImp.spritePixelsToUnits = 10; #else texImp.spritePixelsPerUnit = 10; #endif } texImp.filterMode = FilterMode.Point; AssetDatabase.ImportAsset(path); return(true); }