public static void SaveFile(string DefaultName, Texture2D texture, ImageFileType Extension) { var DoSave = PopX.IO.GetFileWriteImageFunction(Extension); var ExtensionsString = Extension.ToString(); var DefaultDirectory = Application.dataPath; var Filename = UnityEditor.EditorUtility.SaveFilePanel("Save as...", DefaultDirectory, DefaultName, ExtensionsString); if (string.IsNullOrEmpty(Filename)) { throw new System.Exception("Save cancelled"); } /* gr: might still want this on windows if the user can choose a different extension. osx won't allow it * // get the full path * // work out the extension used * ImageFileType? Extension = null; * foreach (var Ext in Extensions) * if (Filename.EndsWith(Ext.ToString())) * Extension = Ext; * if (!Extension.HasValue) * throw new System.Exception("Couldn't determine file extension selected by user"); */ DoSave(Filename, texture); }
/// <summary> /// Return the file extension corresponding to the image file type. /// </summary> /// <param name="fileType">The file type</param> /// <returns>The file extension (for example ".png").</returns> public static string ToFileExtension(this ImageFileType fileType) { switch (fileType) { case ImageFileType.Stride: return(".sdimg"); default: return("." + fileType.ToString().ToLowerInvariant()); } }
/// <summary> /// Return the file extension corresponding to the image file type. /// </summary> /// <param name="fileType">The file type</param> /// <returns>The file extension (for example ".png").</returns> public static string ToFileExtension(this ImageFileType fileType) { switch (fileType) { case ImageFileType.Paradox: return(".pdximage"); default: return("." + fileType.ToString().ToLowerInvariant()); } }
public static void Capture( GraphicsDevice device, string filePath = null, ImageFileType format = ImageFileType.Png ) { if( filePath == null ) { if( !Directory.Exists( defaultFolder ) ) { Directory.CreateDirectory( defaultFolder ); } filePath = Path.Combine( defaultFolder, defaultName + "_" + ( FileCount( defaultFolder ) + 1 ).ToString() + "." + format.ToString().ToLower() ); } device.BackBuffer.Save( filePath, format ); }
/// <exception cref="ArgumentNullException"> /// Thrown when a null reference is passed to a method that does not accept it as a /// valid argument. /// </exception> internal string SearchGalleryAdvancedRequest(string url, string qAll = null, string qAny = null, string qExactly = null, string qNot = null, ImageFileType? fileType = null, ImageSize? imageSize = null) { if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); if (string.IsNullOrWhiteSpace(qAll) && string.IsNullOrWhiteSpace(qAny) && string.IsNullOrWhiteSpace(qExactly) && string.IsNullOrWhiteSpace(qNot)) throw new ArgumentNullException(null, "At least one search parameter must be provided (All | Any | Exactly | Not)."); var query = new StringBuilder(); if (!string.IsNullOrWhiteSpace(qAll)) query.Append($"&q_all={WebUtility.UrlEncode(qAll)}"); if (!string.IsNullOrWhiteSpace(qAny)) query.Append($"&q_any={WebUtility.UrlEncode(qAny)}"); if (!string.IsNullOrWhiteSpace(qExactly)) query.Append($"&q_exactly={WebUtility.UrlEncode(qExactly)}"); if (!string.IsNullOrWhiteSpace(qNot)) query.Append($"&q_not={WebUtility.UrlEncode(qNot)}"); if (fileType != null) query.Append($"&q_type={WebUtility.UrlEncode(fileType.ToString().ToLower())}"); if (imageSize != null) query.Append($"&q_size_px={WebUtility.UrlEncode(imageSize.ToString().ToLower())}"); return $"{url}?{query}".Replace("?&", "?"); }
public static void Capture(GraphicsDevice device, string filePath = null, ImageFileType format = ImageFileType.Png) { if (filePath == null) { if (!Directory.Exists(defaultFolder)) { Directory.CreateDirectory(defaultFolder); } filePath = Path.Combine(defaultFolder, defaultName + "_" + (FileCount(defaultFolder) + 1).ToString() + "." + format.ToString().ToLower()); } device.BackBuffer.Save(filePath, format); }
static public string GetImageFormatExtension(ImageFileType FileType) { return(FileType.ToString()); }
public async Task <string> Save(string filePath, string outputFolder, ImageFileType type) { var opts = new Android.Graphics.BitmapFactory.Options(); opts.InPreferredConfig = Android.Graphics.Bitmap.Config.Argb8888; Android.Graphics.Bitmap bitmap = await Android.Graphics.BitmapFactory.DecodeFileAsync(filePath, opts); var outputpath = Path.Combine(outputFolder, Path.ChangeExtension(Path.GetFileName(filePath), type.ToString())); var stream = new FileStream(outputpath, FileMode.Create); switch (type) { case ImageFileType.PNG: bitmap.Compress(Android.Graphics.Bitmap.CompressFormat.Png, 100, stream); break; case ImageFileType.JPG: bitmap.Compress(Android.Graphics.Bitmap.CompressFormat.Jpeg, 100, stream); break; default: throw new NotImplementedException(); } stream.Close(); return(outputpath); }