Exemplo n.º 1
0
            private void GetRegionInfo(BitmapSource src,bool isMain)
            {
                if (isMain)
                {
                    BitmapImage bitmapImage = (BitmapImage)src;
                    int height = bitmapImage.PixelHeight;
                    int width = bitmapImage.PixelWidth;
                    _mapAspectRatio = width / height;
                    int nStride = (bitmapImage.PixelWidth * bitmapImage.Format.BitsPerPixel + 7) / 8;
                    _MainPixels = new byte[bitmapImage.PixelHeight * nStride];
                    bitmapImage.CopyPixels(_MainPixels, nStride, 0);

                    int maxX = -1, maxY = -1, minX = int.MaxValue, minY = int.MaxValue, sumX = 0, sumY = 0, numColoredPixels = 0;
                    for (int x = 0; x < src.PixelWidth; x++)
                    {
                        for (int y = 0; y < src.PixelHeight; y++)
                        {
                            if (_MainPixels[x * 4 + (y * src.PixelWidth * 4)] != 0)
                            {
                                numColoredPixels += 1;
                                sumX = sumX + x;
                                sumY = sumY + y;
                                if (minY > y) minY = y;
                                if (minX > x) minX = x;
                                if (y > maxY) maxY = y;
                                if (x > maxX) maxX = x;
                            }
                        }
                    }
                    Left = minX;
                    Right = maxX;
                    Top = minY;
                    Bottom = maxY;
                    CenterX = sumX / numColoredPixels;
                    CenterY = sumY / numColoredPixels;
                }
                else
                {
                    BitmapImage bitmapImage = (BitmapImage)src;
                    int height = bitmapImage.PixelHeight;
                    int width = bitmapImage.PixelWidth;
                    _mapAspectRatio = width / height;
                    int nStride = (bitmapImage.PixelWidth * bitmapImage.Format.BitsPerPixel + 7) / 8;
                    _SubDivPixels = new byte[bitmapImage.PixelHeight * nStride];
                    bitmapImage.CopyPixels(_SubDivPixels, nStride, 0);
                    for (int x = 0; x < src.PixelWidth; x++)
                    {
                        for (int y = 0; y < src.PixelHeight; y++)
                        {
                            if (_SubDivPixels[x * 4 + (y * src.PixelWidth * 4)] != 0)
                            {
                                mapColor c = new mapColor(_SubDivPixels[x * 4 + (y * bitmapImage.PixelWidth * 4)],
                        _SubDivPixels[x * 4 + (y * bitmapImage.PixelWidth * 4) + 1],
                            _SubDivPixels[x * 4 + (y * bitmapImage.PixelWidth * 4) + 2],
                                _SubDivPixels[x * 4 + (y * bitmapImage.PixelWidth * 4) + 3]);
                                bool found = false;
                                foreach (mapColor col in colorOuts.Keys)
                                {
                                    if (c.a == col.a && c.b == col.b && c.g == col.g && c.r == col.r)
                                    {
                                        found = true;
                                        break;
                                    }
                                }
                                if (!found)
                                {
                                    InternalRegion internalRegion = new InternalRegion(c);
                                    _regions.Add(internalRegion);
                                    int numArtworks = -1;
                                    colorOuts[c] = "There have been " + numArtworks + " pieces created here";
                                }
                            }
                        }
                    }
                }
            }
Exemplo n.º 2
0
 public InternalRegion(mapColor rgb)
 {
     artworks = new List<ImageData>();
     _rgb = rgb;
 }
Exemplo n.º 3
0
 public bool TestColor(mapColor rgb)
 {
     return ((_rgb.r == rgb.r) && (_rgb.g == rgb.g) && (_rgb.b == rgb.b));
 }