AcTools.Render.Base.Utils.TextureReader.ToPng C# (CSharp) Метод

ToPng() публичный статический Метод

public static ToPng ( DeviceContextHolder holder, byte bytes, bool ignoreAlpha, Format &format ) : byte[]
holder DeviceContextHolder
bytes byte
ignoreAlpha bool
format Format
Результат byte[]
        public static byte[] ToPng(DeviceContextHolder holder, byte[] bytes, bool ignoreAlpha, out Format format) {
            Viewport[] viewports = null;

            try {
                using (var stream = new System.IO.MemoryStream())
                using (var effect = new EffectPpBasic())
                using (var output = TargetResourceTexture.Create(Format.R8G8B8A8_UNorm))
                using (var resource = ShaderResourceView.FromMemory(holder.Device, bytes)) {
                    var texture = (Texture2D)resource.Resource;
                    var loaded = texture.Description;
                    effect.Initialize(holder.Device);

                    format = loaded.Format;
                    output.Resize(holder, loaded.Width, loaded.Height);

                    holder.DeviceContext.ClearRenderTargetView(output.TargetView, Color.Transparent);
                    holder.DeviceContext.OutputMerger.SetTargets(output.TargetView);

                    viewports = holder.DeviceContext.Rasterizer.GetViewports();
                    holder.DeviceContext.Rasterizer.SetViewports(new Viewport(0, 0, loaded.Width, loaded.Height, 0.0f, 1.0f));

                    holder.DeviceContext.OutputMerger.BlendState = null;
                    holder.QuadBuffers.Prepare(holder.DeviceContext, effect.LayoutPT);

                    effect.FxInputMap.SetResource(resource);
                    holder.PrepareQuad(effect.LayoutPT);

                    if (ignoreAlpha) {
                        effect.TechCopyNoAlpha.DrawAllPasses(holder.DeviceContext, 6);
                    } else {
                        effect.TechCopy.DrawAllPasses(holder.DeviceContext, 6);
                    }

                    Texture2D.ToStream(holder.DeviceContext, output.Texture, ImageFileFormat.Png, stream);
                    stream.Position = 0;
                    return stream.GetBuffer();
                }
            } finally {
                if (viewports != null) {
                    holder.DeviceContext.Rasterizer.SetViewports(viewports);
                }
            }
        }
    }
TextureReader