当前位置: 首页>>代码示例>>C#>>正文


C# Texture2D.SaveAsPng方法代码示例

本文整理汇总了C#中Microsoft.Xna.Framework.Graphics.Texture2D.SaveAsPng方法的典型用法代码示例。如果您正苦于以下问题:C# Texture2D.SaveAsPng方法的具体用法?C# Texture2D.SaveAsPng怎么用?C# Texture2D.SaveAsPng使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Xna.Framework.Graphics.Texture2D的用法示例。


在下文中一共展示了Texture2D.SaveAsPng方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Generate

    public static OcclusionMap Generate()
    {
        //Make room for edges which are always walls.
        bool[,] space = new bool[260 - 2, 260 - 2];

        for (int i = 0; i != 200; i++)
        {
            for (int j = 0; j != 200; j++)
            {
                space[i, j] = true;
            }
        }

        Texture2D Map = new Texture2D(Renderer.GraphicsDevice,260, 260);

        Color[] color = new Color[260 * 260];

        for (int i = 0; i != 260; i++)
        {
            for (int j = 0; j != 260; j++)
            {
                color[i * 260 + j] = ( i != 0 && j != 0 && i != 259 && j != 259 && space[i-1,j-1] ? FloorColor : WallColor);
            }
        }

        Map.SetData(color);
        Stream stream = File.Create("test.png");
        Map.SaveAsPng(stream, 260, 260);
        return null;
    }
开发者ID:WJLiddy,项目名称:BasementExplorer,代码行数:30,代码来源:MapGenerator.cs

示例2: Texture2Image

        public static System.Drawing.Image Texture2Image(Texture2D texture)
        {
            if (texture == null)
            {
                return null;
            }

            if (texture.IsDisposed)
            {
                return null;
            }

            //Memory stream to store the bitmap data.
            MemoryStream ms = new MemoryStream();

            //Save the texture to the stream.
            texture.SaveAsPng(ms, texture.Width, texture.Height);

            //Seek the beginning of the stream.
            ms.Seek(0, SeekOrigin.Begin);

            //Create an image from a stream.
            System.Drawing.Image bmp2 = System.Drawing.Bitmap.FromStream(ms);

            //Close the stream, we nolonger need it.
            ms.Close();
            ms = null;
            return bmp2;
        }
开发者ID:KDSBest,项目名称:RPG-Game-XNA,代码行数:29,代码来源:MapEditor.cs

示例3: ConvertToImage

        public System.Drawing.Image ConvertToImage(Texture2D source)
        {
            if (source == null) return null;

            MemoryStream mem = new MemoryStream();
            source.SaveAsPng(mem, source.Width, source.Height);
            return System.Drawing.Image.FromStream(mem);
        }
开发者ID:rykdesjardins,项目名称:pixel-lion,代码行数:8,代码来源:XNAUtils.cs

示例4: SaveTextureData

 //TODO: monogame does not support SaveAsXXX and mono does not implement gzipstream properly
 //TODO: find a fix for linux
 public static string SaveTextureData(Texture2D texture)
 {
     var streamOut = new MemoryStream();
     var width = texture.Width;
     var height = texture.Height;
     texture.SaveAsPng(streamOut, width, height);
     return Convert.ToBase64String(streamOut.ToArray());
 }
开发者ID:SpagAachen,项目名称:Ballz,代码行数:10,代码来源:TextureHelper.cs

示例5: Capture

        /// <summary>
        /// Stores the current contents of the back buffer as a .PNG file.
        /// </summary>
        /// <param name="inGraphicsDevice">GraphicsDevice to grab the back buffer data from.</param>
        /// <param name="inFilename">String containing the name of the file to save.</param>
        /// <returns>True if the file is saved successfully, otherwise false.</returns>
        public static bool Capture(GraphicsDevice inGraphicsDevice,
                                   String inFilename, ScreenCaptureType inCaptureExtension)
        {
            if (inCaptureExtension == ScreenCaptureType.UseJPEG) { inFilename = inFilename + ".jpg"; }
            if (inCaptureExtension == ScreenCaptureType.UsePNG) { inFilename = inFilename + ".png"; }

            // Store the current BackBuffer data in a new array of Color values. This
            // will take what is currently on the BackBuffer; everything current being
            // drawn to the screen.
            Color[] colorData = new Color[inGraphicsDevice.Viewport.Width *
                                          inGraphicsDevice.Viewport.Height];
            inGraphicsDevice.GetBackBufferData<Color>(colorData);

            // Next set the colors into a Texture, ready for saving.
            Texture2D backBufferTexture = new Texture2D(inGraphicsDevice,
                                                        inGraphicsDevice.Viewport.Width,
                                                        inGraphicsDevice.Viewport.Height);
            backBufferTexture.SetData<Color>(colorData, 0, colorData.Length);

            // Create the file after checking whether it exists. This requires a means
            // of altering the intended filename so that it cannot overwrite an existing
            // screen-capture, for instance suffixing an incremental digit onto the file
            // name, but this would have to be saved to avoid overwritten files when the
            // game crashes and the count is lost.
            if (!File.Exists(inFilename))
            {
                using (FileStream fileStream = File.Create(inFilename))
                {
                    // The choice passed in as the 3rd parameter just exists for the sake
                    // of providing options. If one is clearly advantageous to the other
                    // I'll hard-code it to use that instead. But, for now, we allow the
                    // choice between JPEG and PNG. PNG files have transparency.
                    switch (inCaptureExtension)
                    {
                        case ScreenCaptureType.UseJPEG:
                            backBufferTexture.SaveAsJpeg(fileStream,
                                                         inGraphicsDevice.Viewport.Width,
                                                         inGraphicsDevice.Viewport.Height);
                            break;
                        case ScreenCaptureType.UsePNG:
                            backBufferTexture.SaveAsPng(fileStream,
                                                        inGraphicsDevice.Viewport.Width,
                                                        inGraphicsDevice.Viewport.Height);
                            break;
                    }

                    fileStream.Flush();
                }

                return true;
            }

            return false;
        }
开发者ID:BaronVonTeapot,项目名称:Basic,代码行数:60,代码来源:ScreenCapture.cs

示例6: SaveTexture

        void SaveTexture(IResource resource, Texture2D texture)
        {
            if (texture == null) return;

            using (var stream = resource.Create())
            {
                // PNG only.
                texture.SaveAsPng(stream, texture.Width, texture.Height);
                texture.Name = resource.AbsoluteUri;
            }
        }
开发者ID:willcraftia,项目名称:TestBlocks,代码行数:11,代码来源:Image2DLoader.cs

示例7: Write

        public bool Write(string path, Texture2D texture)
        {
            if (!File.Exists(DataFolder + "\\data"))
            {
                Helper.mkdir(DataFolder + "\\data");
            }

            Stream stream = new FileStream(DataFolder + "\\data\\" + path.Replace("/", "-"), FileMode.OpenOrCreate);
            texture.SaveAsPng(stream, texture.Bounds.Width, texture.Bounds.Height);

            return true;
        }
开发者ID:Shard,项目名称:Blueprint-Client,代码行数:12,代码来源:PackageCache.cs

示例8: ImageFromTexture

        public static Image ImageFromTexture(Texture2D Source)
        {
            Image ToReturn;
            MemoryStream MStream = new MemoryStream();
            Source.SaveAsPng(MStream, Source.Width, Source.Height);
            ToReturn = Image.FromStream(MStream);

            MStream.Dispose();
            MStream = null;
            GC.Collect();

            return ToReturn;
        }
开发者ID:CSPshala,项目名称:BeatWars,代码行数:13,代码来源:TextureUtility.cs

示例9: saveScreenshot

 /// <summary>
 /// Opens dialog for user to save screenshot
 /// </summary>
 /// <param name="texture2D">Takes in texture2D for screen information</param>
 private static void saveScreenshot(Texture2D texture2D)
 {
     SaveFileDialog saveScreenshot = new SaveFileDialog();
     saveScreenshot.DefaultExt = ".png";
     saveScreenshot.ShowDialog();
     saveScreenshot.CreatePrompt = true;
     if (saveScreenshot.FileName != string.Empty)
     {
         Stream stream = new FileStream(saveScreenshot.FileName, FileMode.Create);
         texture2D.SaveAsPng(stream, texture2D.Width, texture2D.Height);
         stream.Close();
     }
 }
开发者ID:DuxClarus,项目名称:Uat-Portfolio,代码行数:17,代码来源:Screenshot.cs

示例10: MakeScreenshot

		public void MakeScreenshot(string fileName)
		{
			var width = (int)window.ViewportPixelSize.Width;
			var height = (int)window.ViewportPixelSize.Height;
			using (var dstTexture = new Texture2D(device.NativeDevice, width, height, false,
				device.NativeDevice.PresentationParameters.BackBufferFormat))
			{
				var pixelColors = new Color[width * height];
				device.NativeDevice.GetBackBufferData(pixelColors);
				dstTexture.SetData(pixelColors);
				using (var stream = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write,
					FileShare.ReadWrite))
					dstTexture.SaveAsPng(stream, width, height);
			}
		}
开发者ID:caihuanqing0617,项目名称:DeltaEngine.Xna,代码行数:15,代码来源:XnaScreenshotCapturer.cs

示例11: SetTextureSlot

    public void SetTextureSlot(int _nSlotIdx, Texture2D _tex)
    {
      if (_nSlotIdx < 0 || _nSlotIdx >= SlotsCount)
        return;

      MemoryStream mem = new MemoryStream();

      _tex.SaveAsPng(mem, 256, 256);

      m_imagesSlots[_nSlotIdx] = Image.FromStream(mem);

      Game1.SetTextureSlot(_nSlotIdx, _tex);

      Refresh();
    }
开发者ID:procfxgen,项目名称:MGShaderEditor,代码行数:15,代码来源:TextureSlotsUserControl.cs

示例12: createTexture

        public static void createTexture(
            GraphicsDevice graphics,
            string name, byte format,
            int width, int height,
            uint[] colorData)
        {
            Stream fStream
                = new FileStream(name,
                    FileMode.CreateNew);

            Texture2D outputTexture
                = new Texture2D(graphics,
                    width, height, false, SurfaceFormat.Color);
            outputTexture.SetData<uint>(colorData);
            outputTexture.SaveAsPng(fStream, width, height);
        }
开发者ID:Resinderate,项目名称:SensitiveWillum,代码行数:16,代码来源:TextureHelper.cs

示例13: copyTexture

        //, Texture2D textureB)
        public static void copyTexture(
           GraphicsDevice graphics, string name,
            Texture2D sourceTexture, SurfaceFormat format)
        {
            Stream fStream
                = new FileStream(name, FileMode.CreateNew);

            uint[] colorData = new uint[sourceTexture.Width * sourceTexture.Height];
            sourceTexture.GetData<uint>(colorData);

            Texture2D outputTexture = new Texture2D(graphics,
                                sourceTexture.Width, sourceTexture.Height,
                                    false, format);
            outputTexture.SetData<uint>(colorData);

            outputTexture.SaveAsPng(fStream, outputTexture.Width, outputTexture.Height);
        }
开发者ID:Resinderate,项目名称:SensitiveWillum,代码行数:18,代码来源:TextureHelper.cs

示例14: UpdateUi

        public override sealed void UpdateUi(Object value)
        {
            if (value != _currentTexture) {
                _currentTexture = value as Texture2D;
                if (_currentTexture == null)
                    return;

                using (var pngImage = new MemoryStream()) {
                    _currentTexture.SaveAsPng(pngImage, 20, 20);

                    var bi = new BitmapImage();
                    bi.BeginInit();
                    bi.CacheOption = BitmapCacheOption.OnLoad;
                    bi.DecodePixelWidth = 20;
                    bi.StreamSource = pngImage;
                    bi.EndInit();
                    pngImage.Close();
                    Image.Source = bi;
                }
            }
        }
开发者ID:bartwe,项目名称:Gearset,代码行数:21,代码来源:Texture2DItem.cs

示例15: ScreenShot

        public void ScreenShot()
        {
            int w = GraphicsDevice.PresentationParameters.BackBufferWidth;
            int h = GraphicsDevice.PresentationParameters.BackBufferHeight;

            //force a frame to be drawn (otherwise back buffer is empty)
            Draw(new GameTime());

            //pull the picture from the buffer
            int[] backBuffer = new int[w * h];
            GraphicsDevice.GetBackBufferData(backBuffer);

            //copy into a texture
            Texture2D texture = new Texture2D(GraphicsDevice, w, h, false, GraphicsDevice.PresentationParameters.BackBufferFormat);
            texture.SetData(backBuffer);

            //save to disk
            Stream stream = System.IO.File.OpenWrite("screenshot_" + File + ".png");
            texture.SaveAsPng(stream, w, h);
            stream.Close();
        }
开发者ID:jmtt89,项目名称:Red_Neuronal,代码行数:21,代码来源:Game1.cs


注:本文中的Microsoft.Xna.Framework.Graphics.Texture2D.SaveAsPng方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。