當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。