예제 #1
0
파일: Form.cs 프로젝트: ishkang/Gorgon
        /// <summary>
        /// Function to convert the image to use our custom codec.
        /// </summary>
        private void ConvertImage()
        {
            // The path to our image file for our custom codec.
            string tempPath = Path.ChangeExtension(Path.GetTempPath().FormatDirectory(Path.DirectorySeparatorChar) + Path.GetRandomFileName(), "tvImage");

            try
            {
                // Save the current texture using our useless new custom codec.
                _customCodec.SaveToFile(_image.ConvertToFormat(BufferFormat.R8G8B8A8_UNorm), tempPath);
                _image.Dispose();
                _texture?.Dispose();

                _image = _customCodec.LoadFromFile(tempPath);

                _texture = _image.ToTexture2D(_graphics, new GorgonTexture2DLoadOptions
                {
                    Name = "Converted Texture"
                }).GetShaderResourceView();
            }
            catch
            {
                // Clean up the new texture should we have an exception (this shouldn't happen, better safe than sorry).
                _image?.Dispose();
                throw;
            }
            finally
            {
                try
                {
                    File.Delete(tempPath);
                }
                // ReSharper disable once EmptyGeneralCatchClause
                catch
                {
                    // Intentionally left blank.
                    // If we can't clean up the temp file, then it's no big deal right now.
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Function to perform an export of an image.
        /// </summary>
        /// <param name="file">The file to export.</param>
        /// <param name="image">The image data to export.</param>
        /// <param name="codec">The codec to use when encoding the image.</param>
        /// <returns>The path to the exported file.</returns>
        public FileInfo ExportImage(IContentFile file, IGorgonImage image, IGorgonImageCodec codec)
        {
            _exportDialog.ContentFile   = file;
            _exportDialog.SelectedCodec = codec;
            string exportFilePath = _exportDialog.GetFilename();

            if (string.IsNullOrWhiteSpace(exportFilePath))
            {
                return(null);
            }

            _busyState.SetBusy();

            var result = new FileInfo(exportFilePath);

            _log.Print($"Exporting '{file.Name}' to '{exportFilePath}' as {codec.CodecDescription}", LoggingLevel.Verbose);

            codec.SaveToFile(image, result.FullName);

            _busyState.SetIdle();

            return(result);
        }