SetPixel() публичный Метод

public SetPixel ( int x, int y, System.Drawing.Color color ) : void
x int
y int
color System.Drawing.Color
Результат void
Пример #1
0
        public static void RenderSprite(Sprite sprite, int leftPixel, int topPixel, int pixelWidth, int pixelHeight, ImageData imageData)
        {
            if (sprite.Texture == null || sprite.BlendOperation != BlendOperation.Regular)
            {
                // for now throw an exception, later we may want to handle pure color rendering and stuff like that
                throw new NotImplementedException();

            }

            ImageData spriteTextureImageData = ImageData.FromTexture2D(sprite.Texture);

#if FRB_MDX
            ColorOperation colorOperation = GraphicalEnumerations.TranslateTextureOperationToColorOperation(sprite.ColorOperation);

#else
            ColorOperation colorOperation = sprite.ColorOperation;
#endif

            spriteTextureImageData.ApplyColorOperation(colorOperation, sprite.Red, sprite.Green, sprite.Blue, sprite.Alpha);


            int rightBound = System.Math.Min(imageData.Width, leftPixel + pixelWidth);
            int bottomBound = System.Math.Min(imageData.Height, topPixel + pixelHeight);

            int actualWidth = rightBound - leftPixel;
            int actualHeight = bottomBound - topPixel;



            for (int destinationX = leftPixel; destinationX < rightBound; destinationX++)
            {
                for (int destinationY = topPixel; destinationY < bottomBound; destinationY++)
                {
                    int sourcePixelX = spriteTextureImageData.Width * (destinationX - leftPixel) / pixelWidth;
                    int sourcePixelY = spriteTextureImageData.Height * (destinationY - topPixel) / pixelHeight;

                    Color sourcePixel = spriteTextureImageData.GetPixelColor(sourcePixelX, sourcePixelY);

                    if (sourcePixel.A != 255)
                    {
                        Color destinationPixel = imageData.GetPixelColor(destinationX, destinationY);
#if FRB_MDX
                        sourcePixel = Color.FromArgb(
                            System.Math.Max(sourcePixel.A, destinationPixel.A),
                            (byte)(destinationPixel.R * (255 - sourcePixel.A) / 255.0f + sourcePixel.R * (sourcePixel.A) / 255.0f),
                            (byte)(destinationPixel.G * (255 - sourcePixel.A) / 255.0f + sourcePixel.G * (sourcePixel.A) / 255.0f),
                            (byte)(destinationPixel.B * (255 - sourcePixel.A) / 255.0f + sourcePixel.B * (sourcePixel.A) / 255.0f));

                        // This is probably not accurate, but will work currently.  Eventually we may want to look at how blending is actually performed
#else
                        sourcePixel.R = (byte)(destinationPixel.R * (255 - sourcePixel.A) / 255.0f + sourcePixel.R * (sourcePixel.A) / 255.0f);
                        sourcePixel.G = (byte)(destinationPixel.G * (255 - sourcePixel.A) / 255.0f + sourcePixel.G * (sourcePixel.A) / 255.0f);
                        sourcePixel.B = (byte)(destinationPixel.B * (255 - sourcePixel.A) / 255.0f + sourcePixel.B * (sourcePixel.A) / 255.0f);

                        // This is probably not accurate, but will work currently.  Eventually we may want to look at how blending is actually performed
                        sourcePixel.A = System.Math.Max(sourcePixel.A, destinationPixel.A);
#endif
                    }
                    imageData.SetPixel(destinationX, destinationY, sourcePixel);
                }
            }
        }
Пример #2
0
        private static void RenderLetter(char letter, BitmapFont bitmapFont, ImageData imageData, int x, int y)
        {
            float tvTop = 0;
            float tvBottom = 0;
            float tuLeft = 0;
            float tuRight = 0;

            int textureWidth = bitmapFont.Texture.Width;
            int textureHeight = bitmapFont.Texture.Height;

            bitmapFont.AssignCharacterTextureCoordinates((int)letter, out tvTop, out tvBottom, out tuLeft, out tuRight);
            
            
            float characterHeight = bitmapFont.GetCharacterHeight(letter);

            int pixelLeft = (int)(tuLeft * textureWidth);
            int pixelTop = (int)(tvTop * textureHeight);

            int pixelRight = (int)(tuRight * textureWidth);
            int pixelBottom = (int)(tvBottom * textureWidth);

            float unitPerPixel = (characterHeight / (float)(pixelBottom - pixelTop));

            int pixelFromTop = (int)(bitmapFont.LineHeightInPixels * bitmapFont.DistanceFromTopOfLine((int)letter) / (2));// * .25f);


            for (int sourceY = pixelTop; sourceY < pixelBottom; sourceY++)
            {
                for (int sourceX = pixelLeft; sourceX < pixelRight; sourceX++)
                {
                    Color colorFromSource = sTemporaryTextureBuffer[sourceY * textureHeight + sourceX];

                    if (colorFromSource.A != 0)
                    {

                        imageData.SetPixel(x + (sourceX - pixelLeft), pixelFromTop + y + (sourceY - pixelTop), colorFromSource);
                    }
                }
            }

        }