예제 #1
0
 public Bitmap ToBitmap()
 {
     Bitmap bmp = new Bitmap((int)size, (int)size);
     UnsafeBitmap ubmp = new UnsafeBitmap(bmp);
     ubmp.LockBitmap();
     for (int y = 0; y < size; y++)
     {
         for (int x = 0; x < size; x++)
         {
             byte c = (byte)(data[y * size + x] / 256);
             if (c < 0)
                 c = 0;
             if (c > 255)
                 c = 255;
             PixelData color;
             color.red = color.green = color.blue = c;
             ubmp.SetPixel(x, y, color);
         }
     }
     ubmp.UnlockBitmap();
     return ubmp.Bitmap;
 }
예제 #2
0
        private bool buildSlopemap()
        {
            slopemap = new Bitmap(outputSize, outputSize);

            UnsafeBitmap sm = new UnsafeBitmap(slopemap);
            sm.LockBitmap();
            for (int y = 0; y < outputSize; y++)
            {
                for (int x = 0; x < outputSize; x++)
                {
                    UInt32 height = heightmap.GetHeight(x, y);
                    UInt32 averageHeight = heightmap.SampleHeight(x, y, 3);

                    double slope = (double)Math.Abs((double)height - (double)averageHeight);

                    slope = slope * slopeMultiplier;

                    byte bslope = (byte)(slope);

                    PixelData slopeColor;

                    slopeColor.red = slopeColor.green = slopeColor.blue = bslope;

                    sm.SetPixel(x, y, slopeColor);
                }

                backgroundWorker.ReportProgress((int)(((float)y / (float)outputSize) * 100), "Building slope map...");
            }

            byte maxSlope = 0;
            for (int y = 0; y < outputSize; y++)
            {
                for (int x = 0; x < outputSize; x++)
                {
                    byte v = sm.GetPixel(x, y).red;
                    if (v > maxSlope)
                        maxSlope = v;
                }

                backgroundWorker.ReportProgress((int)(((float)y / (float)outputSize) * 100), "Processing slope map...");
            }

            if (slopeBlur > 0)
            {
                for (int i = 0; i < slopeBlur; i++)
                {
                    backgroundWorker.ReportProgress((int)(((double)i / (double)slopeBlur) * 100), "Blurring slope map...");
                    sm.Blur(1, true);
                }
            }

            sm.UnlockBitmap();

            slopemap = sm.Bitmap;

            return true;
        }