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


C# Texture.CopyToImage方法代码示例

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


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

示例1: SliceAndDice

        public static void SliceAndDice(Vector2f startPoint, Vector2f endPoint, Texture victim, out Texture sliceA,
                                        out Texture sliceB, float repeatsX, float repeatsY)
        {
            //startPoint = new Vector2f(ConvertUnits.ToDisplayUnits(startPoint.X),
            //                          ConvertUnits.ToDisplayUnits(startPoint.Y));
            //endPoint =   new Vector2f(ConvertUnits.ToDisplayUnits(endPoint.X),
            //                          ConvertUnits.ToDisplayUnits(endPoint.Y));

            var input = victim.CopyToImage();

            var outputA = new Image((uint)(input.Size.X * repeatsX), (uint)(input.Size.Y * repeatsY), Color.Transparent);
            var outputB = new Image((uint)(input.Size.X * repeatsX), (uint)(input.Size.Y * repeatsY), Color.Transparent);

            for (uint y = 0; y < input.Size.Y * repeatsY; y++)
            {
                for (uint x = 0; x < input.Size.X * repeatsX; x++)
                {
                    var pos = new Vector2f(x, y);
                    var start = new Vector2(startPoint.X, startPoint.Y);
                    var end = new Vector2(endPoint.X, endPoint.Y);
                    var line = end - start;
                    line.Normalize();
                    if (WhichSideOfLine(startPoint, endPoint, pos))
                        outputA.SetPixel(x, y, input.GetPixel(x % input.Size.X, y % input.Size.Y));
                    else
                        outputB.SetPixel(x, y, input.GetPixel(x % input.Size.X, y % input.Size.Y));
                }
            }

            sliceA = new Texture(outputA);
            sliceB = new Texture(outputB);
        }
开发者ID:RobKellett,项目名称:EdgeCandy,代码行数:32,代码来源:TextureSlicer.cs

示例2: PixelCollider

        /// <summary>
        /// Creates a pixel collider.
        /// </summary>
        /// <param name="source">The source image to create the collider from.</param>
        /// <param name="tags">The tags to register the collider with.</param>
        public PixelCollider(string source, params int[] tags)
        {
            texture = Textures.Load(source);
            collideImage = texture.CopyToImage();

            Width = texture.Size.X;
            Height = texture.Size.Y;

            AddTag(tags);
        }
开发者ID:Kotvitskiy,项目名称:AoS,代码行数:15,代码来源:PixelCollider.cs

示例3: GetBitmask

        uint[] GetBitmask(Texture texture)
        {
            uint[] mask;

            if (!Bitmasks.ContainsKey(texture))
            {
                Image image = texture.CopyToImage();
                mask = CreateBitmask(texture, image);
            }
            else
                return Bitmasks[texture];

            return mask;
        }
开发者ID:Kaev,项目名称:Alieanum,代码行数:14,代码来源:CollisionManager.cs

示例4: LoadContentInitialize

        private static void LoadContentInitialize()
        {
            window = new RenderWindow(
                new VideoMode(800, 600), "Project Title");

            windowSize = new Vector2f(800, 600);
            window.SetFramerateLimit(60);
            window.Closed += (a, b) => { window.Close(); };

            camera2D = new View(cameraPos, new Vector2f(640, 480));



            tempIdleN = new Sprite(new Texture("Content/tempIdleN.png"));
            tempIdleS = new Sprite(new Texture("Content/tempIdleS.png"));
            tempIdleEW = new Sprite(new Texture("Content/tempIdleEW.png"));
            background = new Sprite(new Texture("Content/background.png"));
            basicLevelDec = new Sprite(new Texture("Content/basicLevel_decorMap.png"));


            basicLevelCol = new Texture("Content/basicLevel_collisionMap.png");
            backgroundTexture = basicLevelCol;
            map = backgroundTexture.CopyToImage();

            font = new Font("Content/Font1.ttf");

            click = new SoundBuffer("Content/click.wav");
            SaD = new SoundBuffer("Content/SaD.wav");
            fart = new SoundBuffer("Content/fart.wav");
            crunch = new SoundBuffer("Content/crunch.wav");

            window.TextEntered += (object sender, TextEventArgs e) =>
            {

                if (Keyboard.IsKeyPressed(Keyboard.Key.Back))
                {
                    if (clientPlayer.textCapture.Length > 0)
                        clientPlayer.textCapture = clientPlayer.textCapture.Substring(0, clientPlayer.textCapture.Length - 1);
                }
                else if (Keyboard.IsKeyPressed(Keyboard.Key.Return))
                {
                }
                else if (Keyboard.IsKeyPressed(Keyboard.Key.LControl))
                {
                }
                else if (Keyboard.IsKeyPressed(Keyboard.Key.Tab))
                {
                }
                else
                {
                    clientPlayer.textCapture += e.Unicode;
                }

            };

            window.Closed += (object sender, EventArgs e) =>
            {
                client.Disconnect("Exit");
                System.Threading.Thread.Sleep(100);

            };

        }
开发者ID:libjared,项目名称:jaunt,代码行数:63,代码来源:Program.cs

示例5: CopyToBitmap

        /// <summary>
        /// Copies the pixels from a <see cref="Texture"/> to a <see cref="Bitmap"/>.
        /// </summary>
        /// <param name="texture">The source <see cref="Texture"/>.</param>
        /// <param name="b">The destination <see cref="Bitmap"/>.</param>
        /// <param name="source">The source area to copy.</param>
        static unsafe void CopyToBitmap(Texture texture, Bitmap b, Rectangle source)
        {
            const int bytesPerColor = 4;

            var image = texture.CopyToImage();
            var pixels = image.Pixels;

            // Lock the whole bitmap for write only
            var rect = new Rectangle(0, 0, source.Width, source.Height);
            var data = b.LockBits(rect, ImageLockMode.WriteOnly, b.PixelFormat);

            try
            {
                var srcStride = rect.Width * bytesPerColor;
                var dataStride = data.Stride / bytesPerColor;
                var srcXtimesBPP = source.X * bytesPerColor;
                var srcY = source.Y;

                // Grab the pointer to the pixels array
                fixed (byte* p = pixels)
                {
                    var row = (int*)data.Scan0;

                    // Copy the pixel values byte-by-byte, making sure to copy the RGBA source to the ARGB destination
                    for (var y = 0; y < data.Height; y++)
                    {
                        var srcOff = ((y + srcY) * srcStride) + srcXtimesBPP;

                        for (var x = 0; x < data.Width; x++)
                        {
                            // Masks for getting the 4 bytes in the int
                            const int b0 = 255;
                            const int b1 = b0 << 8;
                            const int b2 = b0 << 16;
                            const int b3 = b0 << 24;

                            // Get the raw value at the source (pixels[]) as an int (instead of grabbing each byte at a time)
                            var raw = *((int*)(p + srcOff));

                            // Convert to the correct format by moving doing the following to the source bytes:
                            //      src 0 -> dst 2 (move left 2 bytes)
                            //      src 1 -> dst 1 (no moving)
                            //      src 2 -> dst 0 (move right 2 bytes)
                            //      src 3 -> dst 3 (no moving)
                            var converted = (raw & (b3 | b1)) | ((raw & b0) << 16) | ((raw & b2) >> 16);

                            // Store the converted result
                            row[x] = converted;

                            // Move the source over 4 bytes
                            srcOff += bytesPerColor;
                        }

                        row += dataStride;
                    }
                }
            }
            finally
            {
                b.UnlockBits(data);
            }
        }
开发者ID:mateuscezar,项目名称:netgore,代码行数:68,代码来源:ImageExtensions.cs


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