コード例 #1
0
ファイル: TileChopper.cs プロジェクト: hxhlb/wwt-tile-sdk
        private void Initialize(Bitmap bitmap)
        {
            this.imageWidth  = bitmap.Width;
            this.imageHeight = bitmap.Height;

            // Compute the maximum level of detail that this image supports.
            // This is a function of size of the image.
            this.MaximumLevelsOfDetail = TileHelper.CalculateMaximumLevel(this.imageHeight, this.imageWidth, this.inputBoundary);

            // Get starting pixel values for x and y
            Helper.LatLongToPixelXY(this.inputBoundary.Bottom, this.inputBoundary.Left, this.MaximumLevelsOfDetail, out startX, out startY);

            // Get ending pixel values for x and y
            Helper.LatLongToPixelXY(this.inputBoundary.Top, this.inputBoundary.Right, this.MaximumLevelsOfDetail, out endX, out endY);

            // Get image data
            this.imageData = TileHelper.BitmapToBytes(bitmap);
        }
コード例 #2
0
ファイル: TileHelper.cs プロジェクト: hxhlb/wwt-tile-sdk
        public static void ToBitmap(int level, int tileX, int tileY, int[] values, IImageTileSerializer serializer, IImageTileSerializer referenceImageSerializer)
        {
            byte[] referenceImage = null;
            using (Bitmap image = new Bitmap(Constants.TileSize, Constants.TileSize, PixelFormat.Format32bppArgb))
            {
                // Set the data row by row
                Rectangle  dimension = new Rectangle(0, 0, Constants.TileSize, Constants.TileSize);
                BitmapData imageData = image.LockBits(dimension, ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
                byte[]     rgb       = new byte[imageData.Stride];
                int        position  = -1;

                if (referenceImageSerializer != null)
                {
                    referenceImage = TileHelper.BitmapToBytes(referenceImageSerializer.Deserialize(level, tileX, tileY));
                }

                for (int pixelY = 0; pixelY < Constants.TileSize; pixelY++)
                {
                    Array.Clear(rgb, 0, rgb.Length);
                    int   pos            = 0;
                    Color referenceColor = Color.White;
                    for (int pixelX = 0; pixelX < Constants.TileSize; pixelX++)
                    {
                        Color color = Color.Transparent;
                        position++;
                        if (referenceImage != null)
                        {
                            if (referenceImage != null &&
                                referenceImage[(position * 4)] == referenceColor.B &&
                                referenceImage[(position * 4) + 1] == referenceColor.G &&
                                referenceImage[(position * 4) + 2] == referenceColor.R)
                            {
                                if (values != null)
                                {
                                    color = Color.FromArgb(values[position]);
                                }
                            }
                        }
                        else
                        {
                            if (values != null)
                            {
                                color = Color.FromArgb(values[position]);
                            }
                        }

                        rgb[pos++] = color.B;
                        rgb[pos++] = color.G;
                        rgb[pos++] = color.R;
                        rgb[pos++] = color.A;
                    }

                    IntPtr p = new IntPtr(imageData.Scan0.ToInt64() + (pixelY * imageData.Stride));
                    System.Runtime.InteropServices.Marshal.Copy(rgb, 0, p, rgb.Length);
                }

                image.UnlockBits(imageData);
                if (serializer != null)
                {
                    serializer.Serialize(image, level, tileX, tileY);
                }

                imageData = null;
                rgb       = null;
            }
        }