public static void ExportFbx([DefaultVar] Animator animator, object[] meshes, object[] animationClips, int startKeyframe, int endKeyframe, bool linear, bool EulerFilter, double filterPrecision, string path, string exportFormat, bool allFrames, bool allBones, bool skins, float boneSize, bool morphs, bool flatInbetween, bool compatibility) { List <MeshRenderer> meshList = null; List <int[]> morphList = null; if (meshes != null) { MeshRenderer[] meshArray = Utility.Convert <MeshRenderer>(meshes); meshList = new List <MeshRenderer>(meshArray); if (morphs) { morphList = new List <int[]>(meshes.Length); for (int i = 0; i < meshes.Length; i++) { morphList.Add(null); } } } ImageFileFormat preferredUncompressedFormat = (string)Properties.Settings.Default["ExportUncompressedAs"] == "BMP" ? ImageFileFormat.Bmp : (ImageFileFormat)(-1); Operations.UnityConverter imp = new Operations.UnityConverter(animator, meshList, skins, morphList, flatInbetween, preferredUncompressedFormat); if (animationClips != null) { AnimationClip[] clipArray = Utility.Convert <AnimationClip>(animationClips); List <AnimationClip> clipList = new List <AnimationClip>(clipArray); imp.ConvertAnimations(clipList); } FbxUtility.Export(path, imp, startKeyframe, endKeyframe, linear, EulerFilter, (float)filterPrecision, exportFormat, allFrames, allBones, skins, boneSize, flatInbetween, compatibility); }
public static void ExportMorphFbx([DefaultVar] Animator animator, object[] meshes, object[] morphs, bool flatInbetween, string path, string exportFormat, bool morphMask, bool skins, float boneSize, bool compatibility) { MeshRenderer[] meshArray = Utility.Convert <MeshRenderer>(meshes); List <MeshRenderer> meshList = new List <MeshRenderer>(meshArray); object[][] morphArray = Utility.Convert <object[]>(morphs); List <int[]> morphList = new List <int[]>(morphs.Length); for (int i = 0; i < morphArray.Length; i++) { int[] morphIndices = null; if (morphArray[i] != null) { double[] doubles = Utility.Convert <double>(morphArray[i]); morphIndices = new int[doubles.Length]; for (int j = 0; j < doubles.Length; j++) { morphIndices[j] = (int)doubles[j]; } } morphList.Add(morphIndices); } ImageFileFormat preferredUncompressedFormat = (string)Properties.Settings.Default["ExportUncompressedAs"] == "BMP" ? ImageFileFormat.Bmp : (ImageFileFormat)(-1); Operations.UnityConverter imp = new Operations.UnityConverter(animator, meshList, skins, morphList, flatInbetween, preferredUncompressedFormat); FbxUtility.ExportMorph(path, imp, exportFormat, morphMask, flatInbetween, skins, boneSize, compatibility); }
public static void SetImageFormat(ref ImageFileFormat ziff, EImageFormat imgFormat) { switch (imgFormat) { case EImageFormat.BMP: ziff = new ImageFileFormatBmp(); break; case EImageFormat.GIF: ziff = new ImageFileFormatGif(); break; case EImageFormat.JPEG: ziff = new ImageFileFormatJpg(); break; case EImageFormat.PNG: ziff = new ImageFileFormatPng(); break; case EImageFormat.TIFF: ziff = new ImageFileFormatTif(); break; } }
/// <summary> /// Saves a volume to a file on disk. /// </summary> /// <param name="volume">The volume.</param> /// <param name="fileName">Name of the file.</param> /// <param name="format">The format.</param> /// <param name="box">The box.</param> /// <param name="palette">The palette.</param> /// <returns>A <see cref="SharpDX.Result" /> object describing the result of the operation.</returns> /// <unmanaged>HRESULT D3DXSaveVolumeToFileW([In] const wchar_t* pDestFile,[In] D3DXIMAGE_FILEFORMAT DestFormat,[In] IDirect3DVolume9* pSrcVolume,[In] const PALETTEENTRY* pSrcPalette,[In] const D3DBOX* pSrcBox)</unmanaged> public static void ToFile(Volume volume, string fileName, ImageFileFormat format, Box box, PaletteEntry[] palette) { unsafe { D3DX9.SaveVolumeToFileW(fileName, format, volume, palette, new IntPtr(&box)); } }
public static void Save(Image image, string fileName, ImageFileFormat format, bool saveAlpha) { using (Stream stream = Storage.OpenFile(fileName, OpenFileMode.Create)) { Save(image, stream, format, saveAlpha); } }
public static Image Load(Stream stream) { PeekStream peekStream = new PeekStream(stream, 64); ImageFileFormat format = DetermineFileFormat(peekStream.GetInitialBytesStream()); return(Load(peekStream, format)); }
public static void SaveImage(Device device, string fileName, ImageFileFormat format) { using (Surface backbuffer = device.GetBackBuffer(0, 0, BackBufferType.Mono)) { SurfaceLoader.Save(fileName, format, backbuffer); } }
/// <summary> /// Saves a texture to file. /// </summary> /// <param name = "context">The device used to save the texture.</param> /// <param name = "texture">The texture to save.</param> /// <param name = "format">The format the texture will be saved as.</param> /// <param name = "fileName">Name of the destination output file where the texture will be saved.</param> /// <returns>A <see cref = "T:SharpDX.Result" /> object describing the result of the operation.</returns> public static void ToFile(DeviceContext context, Resource texture, ImageFileFormat format, string fileName) { //System.Diagnostics.Debug.Assert(typeof(T) == typeof(Texture1D) || typeof(T) == typeof(Texture2D) || // typeof(T) == typeof(Texture3D)); D3DX11.SaveTextureToFile(context, texture, format, fileName); }
public static void SaveUnknownFile(byte[] data, DirectoryInfo directoryInfo) { string fileName = "Unknown_" + Encrypt.SimplexHash.ComputeMD5(data.Length.ToString()); string filePath = Path.Combine(directoryInfo.FullName, fileName); string extension = ""; //Find Extension try { using (MemoryStream stream = new MemoryStream(data)) { ImageFileFormat format = IOUtility.GetImageFormat(stream); if (format != ImageFileFormat.unknown) { extension = "." + format.ToString(); filePath += extension; } } } catch (Exception ex) { GDebug.Log(ex.ToString(), GLogLevel.Warnning); } int num = 2; while (File.Exists(filePath)) { filePath = Path.Combine(directoryInfo.FullName, fileName + num + extension); ++num; } using (FileStream fileStream = new FileStream(filePath, FileMode.Create, FileAccess.ReadWrite)) { fileStream.Write(data, 0, data.Length); } }
private string GetFileExtension(ImageFileFormat imageFileFormat) { switch (imageFileFormat) { case ImageFileFormat.Bmp: return(fileExtBMP); case ImageFileFormat.Emf: case ImageFileFormat.EmfPlus: return(fileExtEMF); case ImageFileFormat.Gif: return(fileExtGIF); case ImageFileFormat.Jpeg: return(fileExtJPG); case ImageFileFormat.Png: return(fileExtPNG); case ImageFileFormat.Svg: return(fileExtSVG); case ImageFileFormat.Tiff: return(fileExtTIFF); default: return(string.Empty); } }
/// <summary> /// Gets the System.Drawing.Imaging equivalent ImageFormat /// </summary> /// <param name="format">The format to convert</param> /// <returns>The System.Drawing.Imaging equivalent ImageFormat</returns> public static ImageFormat GetFormat(ImageFileFormat format) { if (format == ImageFileFormat.Jpeg) { return(ImageFormat.Jpeg); } else if (format == ImageFileFormat.Png) { return(ImageFormat.Png); } else if (format == ImageFileFormat.Bmp) { return(ImageFormat.Bmp); } else if (format == ImageFileFormat.Gif) { return(ImageFormat.Gif); } else if (format == ImageFileFormat.Tiff) { return(ImageFormat.Tiff); } else { throw new BadImageFormatException(); } }
public static void ExportTexture([DefaultVar] UnityParser parser, string name, string path) { string folder = Path.GetDirectoryName(path); if (folder.Length > 0) { folder += "\\"; } folder += Path.GetFileNameWithoutExtension(path); ImageFileFormat preferredUncompressedFormat = (string)Properties.Settings.Default["ExportUncompressedAs"] == "BMP" ? ImageFileFormat.Bmp : (ImageFileFormat)(-1); if (name != "*") { Texture2D tex = parser.GetTexture(name); if (tex != null) { tex.Export(folder, preferredUncompressedFormat); } } else { for (int i = 0; i < parser.Textures.Count; i++) { Texture2D tex = parser.GetTexture(i); tex.Export(folder, preferredUncompressedFormat); } } }
public static System.Drawing.Imaging.ImageFormat ToDrawingFormat(this ImageFileFormat format) { switch (format) { case ImageFileFormat.Bmp: return(System.Drawing.Imaging.ImageFormat.Bmp); case ImageFileFormat.Gif: return(System.Drawing.Imaging.ImageFormat.Gif); case ImageFileFormat.Jpeg: return(System.Drawing.Imaging.ImageFormat.Jpeg); case ImageFileFormat.Png: return(System.Drawing.Imaging.ImageFormat.Png); case ImageFileFormat.Tiff: return(System.Drawing.Imaging.ImageFormat.Tiff); case ImageFileFormat.Wmf: return(System.Drawing.Imaging.ImageFormat.Wmf); default: return(System.Drawing.Imaging.ImageFormat.Bmp); } }
/// <summary> /// Saves a volume to a <see cref="DataStream"/>. /// </summary> /// <param name="volume">The volume.</param> /// <param name="format">The format.</param> /// <returns> /// A <see cref="SharpDX.Result"/> object describing the result of the operation. /// </returns> /// <unmanaged>HRESULT D3DXSaveVolumeToFileInMemory([In] ID3DXBuffer** ppDestBuf,[In] D3DXIMAGE_FILEFORMAT DestFormat,[In] IDirect3DVolume9* pSrcVolume,[In, Buffer] const PALETTEENTRY* pSrcPalette,[In] const void* pSrcBox)</unmanaged> public static DataStream ToStream(Volume volume, ImageFileFormat format) { Blob blob; D3DX9.SaveVolumeToFileInMemory(out blob, format, volume, null, IntPtr.Zero); return(new DataStream(blob)); }
internal MyScreenshot(string path, Vector2 sizeMult, bool ignoreSprites) { SavePath = path ?? GetDefaultScreenshotFilenameWithExtension(); Format = GetFormat(Path.GetExtension(SavePath).ToLower()); SizeMult = sizeMult; IgnoreSprites = ignoreSprites; }
private string getRepairOutputFileName(string inpFile, ref ImageFileFormat format, ref Inlite.ClearImage.EFileFormat ciFormat, bool delete) { //string ext = ""; //switch (cmbOutFormat.SelectedIndex) //{ // case 0: // ext = System.IO.Path.GetExtension(inpFile); // format = ImageFileFormat.inputFileFormat; // ciFormat = Inlite.ClearImage.EFileFormat.ciEXT; // break; // case 1: // ext = ".pdf"; // format = ImageFileFormat.pdf; // ciFormat = Inlite.ClearImage.EFileFormat.cifPDF; // break; // case 2: // ext = ".tif"; // format = ImageFileFormat.tiff; // ciFormat = Inlite.ClearImage.EFileFormat.ciTIFF; // break; // case 3: // ext = ".jpg"; // format = ImageFileFormat.jpeg; // ciFormat = Inlite.ClearImage.EFileFormat.ciJPG; // break; //} //string fileOut = System.IO.Path.GetTempPath() + @"CiRepair" + ext; //if (delete) // System.IO.File.Delete(fileOut); //txtRslt.Text = txtRslt.Text + "Output in: " + fileOut + Environment.NewLine; //txtRslt.Text = txtRslt.Text + "------------------------" + Environment.NewLine; //return fileOut; return(""); }
/// <summary>引数画像形式を読込みできるクラス</summary> public static IEnumerable <ImageClass> CanReadClasses(this ImageFileFormat sourceFormat) { return(new[] { ImageClass.DrawingBitmap }); }
public static Image Load(string fileName, ImageFileFormat format) { using (Stream stream = Storage.OpenFile(fileName, OpenFileMode.Read)) { return(Load(stream, format)); } }
public void Save(string filePath, ImageFileFormat format) { if (Filename == null) { Filename = filePath; } Device.File.Save(filePath, GetBytes(format)); }
public ImageRenderer(IImageRendererSource source, int renderWidth, int renderHeight, ImageFileFormat outputFormat, Color backgroundColor) { _Source = source; _RenderWidth = renderWidth; _RenderHeight = renderHeight; _OutputFormat = outputFormat; _BackgroundColor = backgroundColor; }
/// <summary> /// Saves a texture to file. /// </summary> /// <param name = "texture">The texture to save.</param> /// <param name = "format">The format the texture will be saved as.</param> /// <param name = "fileName">Name of the destination output file where the texture will be saved.</param> /// <returns>A <see cref = "T:SharpDX.Result" /> object describing the result of the operation.</returns> public static void ToFile <T>(T texture, ImageFileFormat format, string fileName) where T : Resource { System.Diagnostics.Debug.Assert(typeof(T) == typeof(Texture1D) || typeof(T) == typeof(Texture2D) || typeof(T) == typeof(Texture3D)); D3DX10.SaveTextureToFile(texture, format, fileName); }
public TerrainProductMetadata(string productUUID, IBoundingBox boundingBox, int width, int height, ImageFileFormat format = 0) { ProductUUID = productUUID; BoundingBox = boundingBox; Width = width; Height = height; Format = format; }
/// <summary> /// Saves a volume to a <see cref="DataStream"/>. /// </summary> /// <param name="volume">The volume.</param> /// <param name="format">The format.</param> /// <param name="box">The box.</param> /// <param name="palette">The palette.</param> /// <returns>A <see cref="SharpDX.Result" /> object describing the result of the operation.</returns> /// <unmanaged>HRESULT D3DXSaveVolumeToFileInMemory([In] ID3DXBuffer** ppDestBuf,[In] D3DXIMAGE_FILEFORMAT DestFormat,[In] IDirect3DVolume9* pSrcVolume,[In, Buffer] const PALETTEENTRY* pSrcPalette,[In] const void* pSrcBox)</unmanaged> public static DataStream ToStream(Volume volume, ImageFileFormat format, Box box, PaletteEntry[] palette) { unsafe { Blob blob; D3DX9.SaveVolumeToFileInMemory(out blob, format, volume, palette, new IntPtr(&box)); return(new DataStream(blob)); } }
public static void DownloadFile(string url, DirectoryInfo directoryInfo) { byte[] data = DownloadData(url); //GetPath Uri uri = new Uri(url); string localPath; if (url.Length > 6 && url.Substring(url.Length - 6) == ":large") { //Twitter localPath = new Uri(url.Substring(0, url.Length - 6)).LocalPath; } else { localPath = uri.LocalPath; } string filePath = Path.Combine(directoryInfo.FullName, Path.GetFileName(localPath)); string fileName = Path.GetFileNameWithoutExtension(filePath); string extension = Path.GetExtension(filePath); //Find Extension if (string.IsNullOrEmpty(extension)) { try { using (MemoryStream stream = new MemoryStream(data)) { ImageFileFormat format = IOUtility.GetImageFormat(stream); if (format != ImageFileFormat.unknown) { extension = "." + format.ToString(); filePath += extension; } else { extension = ""; } } } catch (Exception ex) { GDebug.Log(ex.ToString(), GLogLevel.Warnning); extension = ""; } } int num = 2; while (File.Exists(filePath)) { filePath = Path.Combine(directoryInfo.FullName, fileName + num + extension); ++num; } using (FileStream fileStream = new FileStream(filePath, FileMode.Create, FileAccess.ReadWrite)) { fileStream.Write(data, 0, data.Length); } }
public static Image CaptureScreen(ImageFileFormat fmt = ImageFileFormat.Bmp) { Image img; using (var s = _CaptureScreen()) using (var ds = Surface.ToStream(s, fmt)) { img = Image.FromStream(ds); } return img; }
private bool SaveToFileLoop(FileInfo imageFile, ImageFileFormat fileFormat, int width, int height, int resolution) { var successOverall = false; if (mColorGradients == null || mColorGradients.Count == 0) { var success = SaveToFile(imageFile, fileFormat, width, height, resolution); return(success); } foreach (var colorGradient in mColorGradients) { var matchFound = false; foreach (var axis in Plot.Axes) { var newAxis = axis as LinearColorAxis; if (newAxis == null) { continue; } matchFound = true; newAxis.Palette = colorGradient.Value; newAxis.IsAxisVisible = true; var newFileName = Path.GetFileNameWithoutExtension(imageFile.Name) + "_Gradient_" + colorGradient.Key + imageFile.Extension; FileInfo newFileInfo; if (imageFile.DirectoryName != null) { newFileInfo = new FileInfo(Path.Combine(imageFile.DirectoryName, newFileName)); } else { newFileInfo = new FileInfo(newFileName); } var success = SaveToFile(newFileInfo, fileFormat, width, height, resolution); if (success) { successOverall = true; } } if (!matchFound) { var success = SaveToFile(imageFile, fileFormat, width, height, resolution); return(success); } } return(successOverall); }
public void Save(string filePath, ImageFileFormat format) { if (format == ImageFileFormat.JPEG) { AsJPEG().Save(filePath, true); } else { AsPNG().Save(filePath, true); } }
public static void Save(RenderTarget2D renderTarget, Stream stream, ImageFileFormat format, bool saveAlpha) { if (renderTarget.ColorFormat != 0) { throw new InvalidOperationException("Unsupported color format."); } Image image = new Image(renderTarget.Width, renderTarget.Height); renderTarget.GetData(image.Pixels, 0, new Rectangle(0, 0, renderTarget.Width, renderTarget.Height)); Image.Save(image, stream, format, saveAlpha); }
public Image Screenshot(ImageFileFormat format) { Surface backbuffer = device.GetBackBuffer(0, 0, BackBufferType.Mono); System.IO.Stream s = SurfaceLoader.SaveToStream(format, backbuffer); Image i = Image.FromStream(s); backbuffer.Dispose(); return(i); }
public static ImageFormat ToFormat(this ImageFileFormat format) { switch (format) { case ImageFileFormat.JPEG: return(ImageFormat.Jpeg); default: case ImageFileFormat.PNG: return(ImageFormat.Png); } }
public void Save(string filePath, ImageFileFormat format) { BitmapEncoder encoder = format == ImageFileFormat.JPEG ? (BitmapEncoder) new JpegBitmapEncoder() : new PngBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(Source)); using (var stream = new MemoryStream()) { encoder.Save(stream); System.IO.File.WriteAllBytes(filePath, stream.ToArray()); } }
public OffscreenDirectXDrawer(DirectXScene scene, int width, int height, ImageFileFormat imageFileFormat) { _stopwatch.Restart(); _scene = scene; _effect = scene.Effect; _deviceWorker = scene.DeviceWorker; _device = _deviceWorker.Device; _size = new Size(width, height); AcquireSurfaces(); _deviceWorker.BeforeReset += DisposeSurfaces; _deviceWorker.AfterReset += AcquireSurfacesUnsafe; _deviceWorker.Disposing += DisposeSurfaces; _imageFileFormat = imageFileFormat; _stopwatch.Stop(); LogInfo("Created offscreen drawer in {0}", _stopwatch.ElapsedMilliseconds); }
internal static byte[] ToData(Resource res, byte[] screenData, ImageFileFormat fmt) { try { using (var stream = screenData == null ? new MemoryStream() : new MemoryStream(screenData, true)) { Save(res, stream, fmt); return stream.GetBuffer(); } } catch (Exception e) { MyRender11.Log.WriteLine("MyTextureData.ToData()"); MyRender11.Log.IncreaseIndent(); MyRender11.Log.WriteLine(string.Format("Failed to extract data: {0}", e)); MyRender11.Log.DecreaseIndent(); return null; } }
internal static bool ToFile(Resource res, string path, ImageFileFormat fmt) { try { using (var stream = new FileStream(path, FileMode.Create, FileAccess.Write)) { Save(res, stream, fmt); } return true; } catch (SharpDX.SharpDXException e) { MyRender11.Log.WriteLine("SaveResourceToFile()"); MyRender11.Log.IncreaseIndent(); MyRender11.Log.WriteLine(string.Format("Failed to save screenshot {0}: {1}", path, e)); MyRender11.Log.DecreaseIndent(); return false; } }
public void Save(string filename, ImageFileFormat format) { throw new NotImplementedException(); }
private static void Save(Resource res, Stream stream, ImageFileFormat fmt) { var texture = res as Texture2D; var textureCopy = new Texture2D(MyRender11.Device, new Texture2DDescription { Width = (int)texture.Description.Width, Height = (int)texture.Description.Height, MipLevels = 1, ArraySize = 1, Format = texture.Description.Format, Usage = ResourceUsage.Staging, SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0), BindFlags = BindFlags.None, CpuAccessFlags = CpuAccessFlags.Read, OptionFlags = ResourceOptionFlags.None }); MyRender11.DeviceContext.CopyResource(res, textureCopy); DataStream dataStream; var dataBox = MyRender11.DeviceContext.MapSubresource( textureCopy, 0, 0, MapMode.Read, MapFlags.None, out dataStream); var dataRectangle = new DataRectangle { DataPointer = dataStream.DataPointer, Pitch = dataBox.RowPitch }; var bitmap = new Bitmap( MyRender11.WIC, textureCopy.Description.Width, textureCopy.Description.Height, PixelFormatFromFormat(textureCopy.Description.Format), // TODO: should use some conversion from textureCopy.Description.Format dataRectangle); using (var wicStream = new WICStream(MyRender11.WIC, stream)) { BitmapEncoder bitmapEncoder; switch (fmt) { case ImageFileFormat.Png: bitmapEncoder = new PngBitmapEncoder(MyRender11.WIC, wicStream); break; case ImageFileFormat.Jpg: bitmapEncoder = new JpegBitmapEncoder(MyRender11.WIC, wicStream); break; case ImageFileFormat.Bmp: bitmapEncoder = new BmpBitmapEncoder(MyRender11.WIC, wicStream); break; default: MyRenderProxy.Assert(false, "Unsupported file format."); bitmapEncoder = null; break; } if (bitmapEncoder != null) { using (var bitmapFrameEncode = new BitmapFrameEncode(bitmapEncoder)) { bitmapFrameEncode.Initialize(); bitmapFrameEncode.SetSize(bitmap.Size.Width, bitmap.Size.Height); var pixelFormat = PixelFormat.FormatDontCare; bitmapFrameEncode.SetPixelFormat(ref pixelFormat); bitmapFrameEncode.WriteSource(bitmap); bitmapFrameEncode.Commit(); bitmapEncoder.Commit(); } bitmapEncoder.Dispose(); } } MyRender11.DeviceContext.UnmapSubresource(textureCopy, 0); textureCopy.Dispose(); bitmap.Dispose(); }
/// <summary> /// Initializes a new instance of the <see cref="DrawTexture" /> class. /// </summary> /// <param name="texture"> /// The texture /// </param> /// <param name="position"> /// The position /// </param> /// <param name="format"> /// The texture image format. /// </param> public DrawTexture(Texture texture, Vector2? position = null, ImageFileFormat format = ImageFileFormat.Bmp) : this(position) { this.Texture = texture; this.Bitmap = Image.FromStream(BaseTexture.ToStream(texture, format)) as Bitmap; if (this.Bitmap != null) { this.width = this.Bitmap.Width; this.height = this.Bitmap.Height; } }
/// <summary> /// Saves a volume to a <see cref="DataStream"/>. /// </summary> /// <param name="volume">The volume.</param> /// <param name="format">The format.</param> /// <param name="box">The box.</param> /// <param name="palette">The palette.</param> /// <returns>A <see cref="SharpDX.Result" /> object describing the result of the operation.</returns> /// <unmanaged>HRESULT D3DXSaveVolumeToFileInMemory([In] ID3DXBuffer** ppDestBuf,[In] D3DXIMAGE_FILEFORMAT DestFormat,[In] IDirect3DVolume9* pSrcVolume,[In, Buffer] const PALETTEENTRY* pSrcPalette,[In] const void* pSrcBox)</unmanaged> public static DataStream ToStream(Volume volume, ImageFileFormat format, Box box, PaletteEntry[] palette) { unsafe { Blob blob; D3DX9.SaveVolumeToFileInMemory(out blob, format, volume, palette, new IntPtr(&box)); return new DataStream(blob); } }
/// <summary> /// Saves a volume to a <see cref="DataStream"/>. /// </summary> /// <param name="volume">The volume.</param> /// <param name="format">The format.</param> /// <param name="box">The box.</param> /// <returns> /// A <see cref="SharpDX.Result"/> object describing the result of the operation. /// </returns> /// <unmanaged>HRESULT D3DXSaveVolumeToFileInMemory([In] ID3DXBuffer** ppDestBuf,[In] D3DXIMAGE_FILEFORMAT DestFormat,[In] IDirect3DVolume9* pSrcVolume,[In, Buffer] const PALETTEENTRY* pSrcPalette,[In] const void* pSrcBox)</unmanaged> public static DataStream ToStream(Volume volume, ImageFileFormat format, Box box) { return ToStream(volume, format, box, null); }
/// <summary> /// Exports the contents of the diagram to an image of the given format. /// </summary> /// <param name="imageFormat">Specifies the format of the graphics file.</param> public Image CreateImage(ImageFileFormat imageFormat) { return CreateImage(imageFormat, null, 0, false, Color.White, -1); }
private void ExportBitmapFile(ImageFileFormat imageFormat) { string fileFilter = null; switch (imageFormat) { case ImageFileFormat.Bmp: fileFilter = "Bitmap Picture Files|*.bmp|All Files|*.*"; break; case ImageFileFormat.Gif: fileFilter = "Graphics Interchange Format Files|*.gif|All Files|*.*"; break; case ImageFileFormat.Jpeg: fileFilter = "Joint Photographic Experts Group (JPEG) Files|*.jpeg;*.jpg|All Files|*.*"; break; case ImageFileFormat.Png: fileFilter = "Portable Network Graphics Files|*.png|All Files|*.*"; break; case ImageFileFormat.Tiff: fileFilter = "Tagged Image File Format Files|*.tiff;*.tif|All Files|*.*"; break; default: throw new NShapeUnsupportedValueException(imageFormat); } saveFileDialog.Filter = fileFilter; if (saveFileDialog.ShowDialog() == DialogResult.OK) { using (Image image = GetImageFromDiagram(imageFormat)) { if (image != null) GdiHelpers.SaveImageToFile(image, saveFileDialog.FileName, imageFormat, 100); } } }
private string GetFileExtension(ImageFileFormat imageFileFormat) { switch (imageFileFormat) { case ImageFileFormat.Bmp: return fileExtBMP; case ImageFileFormat.Emf: case ImageFileFormat.EmfPlus: return fileExtEMF; case ImageFileFormat.Gif: return fileExtGIF; case ImageFileFormat.Jpeg: return fileExtJPG; case ImageFileFormat.Png: return fileExtPNG; case ImageFileFormat.Svg: return fileExtSVG; case ImageFileFormat.Tiff: return fileExtTIFF; default: return string.Empty; } }
private Image GetImageFromDiagram(ImageFileFormat imageFormat) { Image result = null; Color backColor = Color.Transparent; if (CurrentDisplay.SelectedShapes.Count > 0) result = CurrentDisplay.Diagram.CreateImage(imageFormat, CurrentDisplay.SelectedShapes.BottomUp, CurrentDisplay.GridSize, false, backColor); else result = CurrentDisplay.Diagram.CreateImage(imageFormat, null, 0, true, backColor); return result; }
private string GetFileExtension(ImageFileFormat imageFileFormat) { switch (imageFileFormat) { case ImageFileFormat.Bmp: return "bmp"; case ImageFileFormat.Emf: case ImageFileFormat.EmfPlus: return "emf"; case ImageFileFormat.Gif: return "gif"; case ImageFileFormat.Jpeg: return "jpg"; case ImageFileFormat.Png: return "png"; case ImageFileFormat.Svg: return "svg"; case ImageFileFormat.Tiff: return "tiff"; default: return string.Empty; } }
/// <summary> /// Saves the current view to file. /// </summary> /// <param name="filePath">Path and filename of output file. /// Extension is used to determine the image format.</param> public void SaveScreenshot(string filePath) { if(m_Device3d == null) return; FileInfo saveFileInfo = new FileInfo(filePath); string ext = saveFileInfo.Extension.Replace(".",""); try { this.saveScreenShotImageFileFormat = (ImageFileFormat) Enum.Parse(typeof(ImageFileFormat), ext, true ); } catch(ArgumentException) { throw new ApplicationException("Unknown file type/file extension for file '"+filePath+"'. Unable to save."); } if(!saveFileInfo.Directory.Exists) saveFileInfo.Directory.Create(); this.saveScreenShotFilePath = filePath; }
private void ExportMetaFile(ImageFileFormat imageFormat) { saveFileDialog.Filter = "Enhanced Meta Files|*.emf|All Files|*.*"; if (saveFileDialog.ShowDialog() == DialogResult.OK) { using (Image image = GetImageFromDiagram(imageFormat)) { if (image != null) GdiHelpers.SaveImageToFile(image, saveFileDialog.FileName, imageFormat); } } }
/// <summary> /// Exports the part of the diagram that encloses all given shapes to an image of the given format. /// Pass null/Nothing for Parameter shapes in order to expor the whole diagram area. /// </summary> /// <param name="imageFormat">Specifies the format of the graphics file.</param> /// <param name="shapes">The shapes that should be drawn. If null/Nothing, the whole diagram area will be exported.</param> /// <param name="margin">Specifies the thickness of the margin around the exported diagram area.</param> public Image CreateImage(ImageFileFormat imageFormat, IEnumerable<Shape> shapes, int margin) { return CreateImage(imageFormat, shapes, margin, false, Color.White, -1); }
private void pngRadioButton_CheckedChanged(object sender, EventArgs e) { if (pngRadioButton.Checked) { imageFormat = ImageFileFormat.Png; descriptionLabel.Text = pngDescription; UpdateFileExtension(); EnableResolutionAndQualitySelection(); RefreshPreview(); } }
//private static void DrawScene() //{ // DrawGameScene(true, true); // if (m_screenshot.HasValue) // { // if(m_screenshot.Value.SizeMult == Vector2.One) // { // SaveScreenshotFromResource(Backbuffer.m_resource); // } // else // { // TakeCustomSizedScreenshot(m_screenshot.Value.SizeMult); // } // } // TransferPerformanceStats(); //} static void SaveResourceToFile(Resource res, string path, ImageFileFormat fmt) { try { Resource.ToFile(MyRender11.Context, res, fmt, path); MyRenderProxy.ScreenshotTaken(true, path, false); } catch (SharpDX.SharpDXException e) { MyRender11.Log.WriteLine("SaveResourceToFile()"); MyRender11.Log.IncreaseIndent(); MyRender11.Log.WriteLine(String.Format("Failed to save screenshot {0}: {1}", path, e)); MyRender11.Log.DecreaseIndent(); MyRenderProxy.ScreenshotTaken(false, path, false); } }
public void TakeScreenshot(string file, ImageFileFormat format) { lock (renderLockObj) { rendering = true; } Texture tex = renderContext.RenderToTexture(null, Size.Empty); TextureLoader.Save(file, format, tex); lock (renderLockObj) { rendering = false; } }
/// <summary> /// Exports the part of the diagram that encloses all given shapes (plus margin on each side) to an image of the given format. /// Pass null/Nothing for Parameter shapes in order to expor the whole diagram area. /// </summary> /// <param name="imageFormat">Specifies the format of the graphics file.</param> /// <param name="shapes">The shapes that should be drawn. If null/Nothing, the whole diagram area will be exported.</param> /// <param name="margin">Specifies the thickness of the margin around the exported diagram area.</param> /// <param name="withBackground">Specifies whether the diagram's background should be exported to the graphics file.</param> /// <param name="backgroundColor">Specifies a color for the exported image's background. /// If the diagram is exported with background, the diagram's background will be drawn over the specified background color.</param> public Image CreateImage(ImageFileFormat imageFormat, IEnumerable<Shape> shapes, int margin, bool withBackground, Color backgroundColor) { return CreateImage(imageFormat, shapes, margin, withBackground, backgroundColor, -1); }
private void jpgRadioButton_CheckedChanged(object sender, EventArgs e) { if (jpgRadioButton.Checked) { imageFormat = ImageFileFormat.Jpeg; descriptionLabel.Text = jpgDescription; UpdateFileExtension(); EnableResolutionAndQualitySelection(); backColorCheckBox.Checked = true; RefreshPreview(); } }
/// <summary> /// Saves a volume to a <see cref="DataStream"/>. /// </summary> /// <param name="volume">The volume.</param> /// <param name="format">The format.</param> /// <returns> /// A <see cref="SharpDX.Result"/> object describing the result of the operation. /// </returns> /// <unmanaged>HRESULT D3DXSaveVolumeToFileInMemory([In] ID3DXBuffer** ppDestBuf,[In] D3DXIMAGE_FILEFORMAT DestFormat,[In] IDirect3DVolume9* pSrcVolume,[In, Buffer] const PALETTEENTRY* pSrcPalette,[In] const void* pSrcBox)</unmanaged> public static DataStream ToStream(Volume volume, ImageFileFormat format) { Blob blob; D3DX9.SaveVolumeToFileInMemory(out blob, format, volume, null, IntPtr.Zero); return new DataStream(blob); }
/// <summary> /// Saves a volume to a file on disk. /// </summary> /// <param name="volume">The volume.</param> /// <param name="fileName">Name of the file.</param> /// <param name="format">The format.</param> /// <returns> /// A <see cref="SharpDX.Result"/> object describing the result of the operation. /// </returns> /// <unmanaged>HRESULT D3DXSaveVolumeToFileW([In] const wchar_t* pDestFile,[In] D3DXIMAGE_FILEFORMAT DestFormat,[In] IDirect3DVolume9* pSrcVolume,[In] const PALETTEENTRY* pSrcPalette,[In] const D3DBOX* pSrcBox)</unmanaged> public static void ToFile(Volume volume, string fileName, ImageFileFormat format) { D3DX9.SaveVolumeToFileW(fileName, format, volume, null, IntPtr.Zero); }
/// <summary> /// Exports the part of the diagram that encloses all given shapes to an image of the given format. /// Pass null/Nothing for Parameter shapes in order to expor the whole diagram area. /// </summary> /// <param name="imageFormat">Specifies the format of the graphics file.</param> /// <param name="shapes">The shapes that should be drawn. If null/Nothing, the whole diagram area will be exported.</param> /// <param name="withBackground">Specifies whether the diagram's background should be exported to the graphics file.</param> public Image CreateImage(ImageFileFormat imageFormat, IEnumerable<Shape> shapes, bool withBackground) { return CreateImage(imageFormat, shapes, 0, withBackground, Color.White, -1); }
/// <summary> /// Saves a volume to a file on disk. /// </summary> /// <param name="volume">The volume.</param> /// <param name="fileName">Name of the file.</param> /// <param name="format">The format.</param> /// <param name="box">The box.</param> /// <returns> /// A <see cref="SharpDX.Result"/> object describing the result of the operation. /// </returns> /// <unmanaged>HRESULT D3DXSaveVolumeToFileW([In] const wchar_t* pDestFile,[In] D3DXIMAGE_FILEFORMAT DestFormat,[In] IDirect3DVolume9* pSrcVolume,[In] const PALETTEENTRY* pSrcPalette,[In] const D3DBOX* pSrcBox)</unmanaged> public static void ToFile(Volume volume, string fileName, ImageFileFormat format, Box box) { ToFile(volume, fileName, format, box, null); }
/// <summary> /// Exports the part of the diagram that encloses all given shapes (plus margin on each side) to an image of the given format. /// Pass null/Nothing for Parameter shapes in order to expor the whole diagram area. /// </summary> /// <param name="imageFormat">Specifies the format of the graphics file.</param> /// <param name="shapes">The shapes that should be drawn. If null/Nothing, the whole diagram area will be exported.</param> /// <param name="margin">Specifies the thickness of the margin around the exported diagram area.</param> /// <param name="withBackground">Specifies whether the diagram's background should be exported to the graphics file.</param> /// <param name="backgroundColor">Specifies a color for the exported image's background. /// If the diagram is exported with background, the diagram's background will be drawn over the specified background color.</param> /// <param name="dpi">Specifies the resolution for the export file. Only applies to pixel based image file formats.</param> public Image CreateImage(ImageFileFormat imageFormat, IEnumerable<Shape> shapes, int margin, bool withBackground, Color backgroundColor, int dpi) { Image result = null; // Get/Create info graphics bool disposeInfoGfx; Graphics infoGraphics; if (DisplayService != null) { infoGraphics = DisplayService.InfoGraphics; disposeInfoGfx = false; } else { infoGraphics = Graphics.FromHwnd(IntPtr.Zero); disposeInfoGfx = true; } try { // If dpi value is not valid, get current dpi from display service if (dpi <= 0) dpi = (int)Math.Round((infoGraphics.DpiX + infoGraphics.DpiY) / 2f); // Get bounding rectangle around the given shapes Rectangle imageBounds = Rectangle.Empty; if (shapes == null) { imageBounds.X = imageBounds.Y = 0; imageBounds.Width = Width; imageBounds.Height = Height; } else { int left, top, right, bottom; left = top = int.MaxValue; right = bottom = int.MinValue; // Calculate the bounding rectangle of the given shapes Rectangle boundingRect = Rectangle.Empty; foreach (Shape shape in shapes) { boundingRect = shape.GetBoundingRectangle(true); if (boundingRect.Left < left) left = boundingRect.Left; if (boundingRect.Top < top) top = boundingRect.Top; if (boundingRect.Right > right) right = boundingRect.Right; if (boundingRect.Bottom > bottom) bottom = boundingRect.Bottom; } if (Geometry.IsValid(left, top, right, bottom)) imageBounds = Rectangle.FromLTRB(left, top, right, bottom); } imageBounds.Inflate(margin, margin); imageBounds.Width += 1; imageBounds.Height += 1; bool originalQualitySetting = this.HighQualityRendering; HighQualityRendering = true; UpdateBrushes(); float scaleX = 1, scaleY = 1; switch (imageFormat) { case ImageFileFormat.Svg: throw new NotImplementedException(); case ImageFileFormat.Emf: case ImageFileFormat.EmfPlus: // Create MetaFile and graphics context IntPtr hdc = infoGraphics.GetHdc(); try { Rectangle bounds = Rectangle.Empty; bounds.Size = imageBounds.Size; result = new Metafile(hdc, bounds, MetafileFrameUnit.Pixel, (imageFormat == ImageFileFormat.Emf) ? EmfType.EmfOnly : EmfType.EmfPlusDual, Name); } finally { infoGraphics.ReleaseHdc(hdc); } break; case ImageFileFormat.Bmp: case ImageFileFormat.Gif: case ImageFileFormat.Jpeg: case ImageFileFormat.Png: case ImageFileFormat.Tiff: int imgWidth = imageBounds.Width; int imgHeight = imageBounds.Height; if (dpi > 0 && dpi != infoGraphics.DpiX || dpi != infoGraphics.DpiY) { scaleX = dpi / infoGraphics.DpiX; scaleY = dpi / infoGraphics.DpiY; imgWidth = (int)Math.Round(scaleX * imageBounds.Width); imgHeight = (int)Math.Round(scaleY * imageBounds.Height); } result = new Bitmap(Math.Max(1, imgWidth), Math.Max(1, imgHeight)); ((Bitmap)result).SetResolution(dpi, dpi); break; default: throw new NShapeUnsupportedValueException(typeof(ImageFileFormat), imageFormat); } // Draw diagram using (Graphics gfx = Graphics.FromImage(result)) { GdiHelpers.ApplyGraphicsSettings(gfx, RenderingQuality.MaximumQuality); // Fill background with background color if (backgroundColor.A < 255) { if (imageFormat == ImageFileFormat.Bmp || imageFormat == ImageFileFormat.Jpeg) { // For image formats that do not support transparency, fill background with the RGB part of // the given backgropund color gfx.Clear(Color.FromArgb(255, backgroundColor)); } else if (backgroundColor.A > 0) { // Skip filling background for meta files if transparency is 100%: // Filling Background with Color.Transparent causes graphical glitches with many applications gfx.Clear(backgroundColor); } } else { // Graphics.Clear() does not work as expected for classic EMF (fills only the top left pixel // instead of the whole graphics context). if (imageFormat == ImageFileFormat.Emf) { using (SolidBrush brush = new SolidBrush(backgroundColor)) gfx.FillRectangle(brush, gfx.ClipBounds); } else gfx.Clear(backgroundColor); } // Transform graphics (if necessary) gfx.TranslateTransform(-imageBounds.X, -imageBounds.Y, MatrixOrder.Prepend); if (scaleX != 1 || scaleY != 1) gfx.ScaleTransform(scaleX, scaleY, MatrixOrder.Append); // Draw diagram background if (withBackground) DrawBackground(gfx, imageBounds); // Draw diagram shapes if (shapes == null) { foreach (Shape shape in diagramShapes.BottomUp) shape.Draw(gfx); } else { // Add shapes to ShapeCollection (in order to maintain zOrder while drawing) int cnt = (shapes is ICollection) ? ((ICollection)shapes).Count : -1; ShapeCollection shapeCollection = new ShapeCollection(cnt); foreach (Shape s in shapes) { // Sort out duplicate references to shapes (as they can occur in the result of Diagram.FindShapes()) if (shapeCollection.Contains(s)) continue; shapeCollection.Add(s, s.ZOrder); } // Draw shapes foreach (Shape shape in shapeCollection.BottomUp) shape.Draw(gfx); shapeCollection.Clear(); } // Reset transformation gfx.ResetTransform(); } // Restore original graphics settings HighQualityRendering = originalQualitySetting; UpdateBrushes(); return result; } finally { if (disposeInfoGfx) GdiHelpers.DisposeObject(ref infoGraphics); } }