GetPixelColor() public méthode

public GetPixelColor ( int x, int y ) : System.Drawing.Color
x int
y int
Résultat System.Drawing.Color
        public void Blit(ImageData source, Rectangle sourceRectangle, Point destination)
        {
            for (int y = 0; y < sourceRectangle.Height; y++)
            {
                for (int x = 0; x < sourceRectangle.Width; x++)
                {
                    int sourceX = x + sourceRectangle.X;
                    int sourceY = y + sourceRectangle.Y;

                    int destinationX = x + destination.X;
                    int destinationY = y + destination.Y;

                    this.SetPixel(destinationX, destinationY, source.GetPixelColor(sourceX, sourceY));
                }
            }
        }
        private static List <Bitmap> GetBitmapList()
        {
            List <Bitmap> bitmaps = new List <Bitmap>();

            for (int i = 0; i < SelectedState.Self.SelectedChain.Frames.Count; i++)
            {
                var frame = SelectedState.Self.SelectedChain.Frames[i];

                var texture = WireframeManager.Self.GetTextureForFrame(frame);
                if (texture != null)
                {
                    FlatRedBall.Graphics.Texture.ImageData imageData =
                        ImageData.FromTexture2D(texture);

                    int left   = Math.MathFunctions.RoundToInt(frame.LeftCoordinate * texture.Width);
                    int right  = Math.MathFunctions.RoundToInt(frame.RightCoordinate * texture.Width);
                    int top    = Math.MathFunctions.RoundToInt(frame.TopCoordinate * texture.Height);
                    int bottom = Math.MathFunctions.RoundToInt(frame.BottomCoordinate * texture.Height);

                    int width  = right - left;
                    int height = bottom - top;

                    Bitmap bitmap = new Bitmap(width, height);
                    bitmaps.Add(bitmap);
                    for (int ySource = top; ySource < bottom; ySource++)
                    {
                        for (int xSource = left; xSource < right; xSource++)
                        {
                            int yDestination = ySource - top;
                            int xDestination = xSource - left;

                            Microsoft.Xna.Framework.Color sourceColor      = imageData.GetPixelColor(xSource, ySource);
                            System.Drawing.Color          destinationColor = Color.FromArgb(
                                sourceColor.A,
                                sourceColor.R,
                                sourceColor.G,
                                sourceColor.B);

                            bitmap.SetPixel(xDestination, yDestination, destinationColor);
                        }
                    }
                }
            }
            return(bitmaps);
        }
        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);
                }
            }
        }
Exemple #4
0
        public void Blit(ImageData source, Rectangle sourceRectangle, Point destination)
        {
            for (int y = 0; y < sourceRectangle.Height; y++)
            {
                for (int x = 0; x < sourceRectangle.Width; x++)
                {
                    int sourceX = x + sourceRectangle.X;
                    int sourceY = y + sourceRectangle.Y;

                    int destinationX = x + destination.X;
                    int destinationY = y + destination.Y;

                    this.SetPixel(destinationX, destinationY, source.GetPixelColor(sourceX, sourceY));
                }
            }
        }