Пример #1
0
        public RandomRectangles(Bitmap fullScreenBitmap, Font DisplayFont)
        {
            Random random = new Random();

            fullScreenBitmap.Clear();
            fullScreenBitmap.Flush();
            int xCornerRadius;
            int yCornerRadius;

            for (int i = 0; i < 100; i++)
            {
                Color fillColor = (nanoFramework.Presentation.Media.Color)random.Next(0xFFFFFF);

                if (i % 2 == 0)
                {
                    xCornerRadius = random.Next(2, 40);
                    yCornerRadius = random.Next(2, 40);
                }
                else
                {
                    xCornerRadius = 0;
                    yCornerRadius = 0;
                }
                fullScreenBitmap.DrawRectangle((nanoFramework.Presentation.Media.Color)random.Next(0xFFFFFF), random.Next(1),
                                               random.Next(fullScreenBitmap.Width), random.Next(fullScreenBitmap.Height - 20), random.Next(fullScreenBitmap.Width), random.Next(fullScreenBitmap.Height - 20), xCornerRadius, yCornerRadius, fillColor, 0, 0, fillColor, 0, 0, (ushort)random.Next(256));
                InformationBar.DrawInformationBar(fullScreenBitmap, DisplayFont, InfoBarPosition.bottom, $"Rectangle Number {i}");
                fullScreenBitmap.Flush();
            }
        }
Пример #2
0
 public SetPixels(Bitmap fullScreenBitmap, Font DisplayFont)
 {
     fullScreenBitmap.Clear();
     fullScreenBitmap.Flush();
     for (int i = 0; i < fullScreenBitmap.Height; ++i)
     {
         fullScreenBitmap.SetPixel(i, i, (Color)((255 - i) << 16));
     }
     for (int i = 0; i < fullScreenBitmap.Height; i += 2)
     {
         fullScreenBitmap.SetPixel(fullScreenBitmap.Height - i, i, (Color)(i << 8));
     }
     InformationBar.DrawInformationBar(fullScreenBitmap, DisplayFont, InfoBarPosition.bottom, "Set individual Pixels");
     fullScreenBitmap.Flush();
 }
Пример #3
0
        public StretchImage(Bitmap fullScreenBitmap, Font DisplayFont)
        {
            Bitmap bmWaterfall = new Bitmap(WaterFallJpg.WaterFall, Bitmap.BitmapImageType.Jpeg);

            fullScreenBitmap.Clear();
            fullScreenBitmap.Flush();
            fullScreenBitmap.DrawImage(0, 0, bmWaterfall, 0, 0, bmWaterfall.Width, bmWaterfall.Height);
            fullScreenBitmap.Flush();
            for (int i = 0; i < 35; i++)
            {
                fullScreenBitmap.StretchImage(0, 0, bmWaterfall, bmWaterfall.Width + (i + 1) * 7, bmWaterfall.Height + (i + 1) * 7, 255);
                InformationBar.DrawInformationBar(fullScreenBitmap, DisplayFont, InfoBarPosition.bottom, "Stretch Image");
                fullScreenBitmap.Flush();
            }
            bmWaterfall.Dispose();
        }
Пример #4
0
        public TileImage(Bitmap fullScreenBitmap, Font DisplayFont)
        {
            //Bitmap btn = new Bitmap(WaterFallJpg.WaterFall, Bitmap.BitmapImageType.Jpeg);
            Bitmap btn = new Bitmap(PandaGif.Panda, Bitmap.BitmapImageType.Gif);

            fullScreenBitmap.Clear();
            fullScreenBitmap.Flush();

            fullScreenBitmap.DrawRectangle(Color.White, 0, 0, 0, fullScreenBitmap.Width, fullScreenBitmap.Height, 0, 0, Color.White, 0, 0, 0, 0, 0, 256);
            Font fntComicSansMS16 = Resource.GetFont(Resource.FontResources.ComicSansMS16);

            fullScreenBitmap.DrawText("Tile Image Example", fntComicSansMS16, Color.Black, 10, 0);
            fullScreenBitmap.TileImage(20, 20, btn, fullScreenBitmap.Width - 50, fullScreenBitmap.Height - 50, 256);
            InformationBar.DrawInformationBar(fullScreenBitmap, DisplayFont, InfoBarPosition.bottom, "Tile Image");
            fullScreenBitmap.Flush();
            btn.Dispose();
        }
Пример #5
0
        public RandomEllipses(Bitmap fullScreenBitmap, Font DisplayFont)
        {
            Random random = new Random();

            fullScreenBitmap.Clear();
            fullScreenBitmap.Flush();
            for (int i = 0; i < 100; i++)
            {
                int radiusX = random.Next(200);
                int radiusY = random.Next(200);

                fullScreenBitmap.DrawEllipse((nanoFramework.Presentation.Media.Color)random.Next(0xFFFFFF), 1,
                                             random.Next(fullScreenBitmap.Width), random.Next(fullScreenBitmap.Height - 20), radiusX, radiusY, 0, 0, 0, 0, 0, 0, 0);
                InformationBar.DrawInformationBar(fullScreenBitmap, DisplayFont, InfoBarPosition.bottom, $"Ellipse Number {i}");
                fullScreenBitmap.Flush();
            }
        }
Пример #6
0
        public RandomDrawLine(Bitmap fullScreenBitmap, Font DisplayFont)
        {
            Random random = new Random();

            fullScreenBitmap.Clear();
            fullScreenBitmap.Flush();
            fullScreenBitmap.DrawText("Random Line Drawing", DisplayFont, Color.AliceBlue, 0, 0);

            for (int i = 100; i > 0; i--)
            {
                fullScreenBitmap.DrawLine((Color)random.Next(0xFFFFFF),
                                          1,
                                          random.Next(fullScreenBitmap.Width),
                                          random.Next(fullScreenBitmap.Height - 22),
                                          random.Next(fullScreenBitmap.Width),
                                          random.Next(fullScreenBitmap.Height));
                InformationBar.DrawInformationBar(fullScreenBitmap, DisplayFont, InfoBarPosition.bottom, $"Line Number {i}");
                fullScreenBitmap.Flush();
            }
        }
Пример #7
0
        public SliceScaling9(Bitmap fullScreenBitmap, Font DisplayFont)
        {
            Font fontHeading = Resource.GetFont(Resource.FontResources.ComicSansMS16);

            fullScreenBitmap.Clear();
            fullScreenBitmap.Flush();

            fullScreenBitmap.DrawText($"Scale image", fontHeading, Color.Beige, 0, 0);
            fullScreenBitmap.DrawRectangle(Color.White, 0, 0, 0, fullScreenBitmap.Width, fullScreenBitmap.Height, 0, 0, Color.White, 0, 0, 0, 0, 0, 256);

            Bitmap bmpScaleWaterFall = new Bitmap(WaterFallJpg.WaterFall, Bitmap.BitmapImageType.Jpeg);

            bmpScaleWaterFall.MakeTransparent(ColorUtility.ColorFromRGB(255, 0, 255));
            fullScreenBitmap.Scale9Image(30, 30, fullScreenBitmap.Width / 3, fullScreenBitmap.Height / 3, bmpScaleWaterFall, 6, 6, 6, 6, 256);
            fullScreenBitmap.Scale9Image(fullScreenBitmap.Width / 2, fullScreenBitmap.Height / 2, fullScreenBitmap.Width / 3, 30, bmpScaleWaterFall, 6, 6, 6, 6, 256);
            fullScreenBitmap.Scale9Image(30, fullScreenBitmap.Height / 2, 30, fullScreenBitmap.Height / 3, bmpScaleWaterFall, 6, 6, 6, 6, 256);
            fullScreenBitmap.Scale9Image(fullScreenBitmap.Width / 2, 30, 30, 30, bmpScaleWaterFall, 6, 6, 6, 6, 256);
            bmpScaleWaterFall.Dispose();

            InformationBar.DrawInformationBar(fullScreenBitmap, DisplayFont, InfoBarPosition.bottom, "9 Slice Scaling ( Scale 9 grid) ");
            fullScreenBitmap.Flush();
        }
Пример #8
0
        public RotateImage(Bitmap fullScreenBitmap, Font DisplayFont)
        {
            Bitmap waterFall = new Bitmap(WaterFallJpg.WaterFall, Bitmap.BitmapImageType.Jpeg);

            try
            {
                int shorterSide = Math.Min(fullScreenBitmap.Width, fullScreenBitmap.Height);
                // Calculate an image size for the waterFall bitmap that will fit inside the bounds of the destination bitmap
                // The diaganol of the image is the longest size
                Single diagonalLength = Math.Sqrt(waterFall.Width * waterFall.Width + waterFall.Height * waterFall.Height);
                Single scaleFactor    = shorterSide / diagonalLength;

                // Stretch the watefall image into the large size
                int    scaledImageWidth  = (int)(waterFall.Width * scaleFactor);
                int    scaledImageHeight = (int)(waterFall.Height * scaleFactor);
                Bitmap scaledImage       = new Bitmap(scaledImageWidth, scaledImageHeight);
                scaledImage.StretchImage(0, 0, waterFall, scaledImageWidth, scaledImageHeight, 0xFFFF);

                // Create a rectangle in the middle where the image will be displayed
                // The same size as the stretched waterfall
                Rect outputRectangle = new Rect {
                    x = (fullScreenBitmap.Width - scaledImageWidth) / 2, y = (fullScreenBitmap.Height - scaledImageHeight) / 2, width = scaledImageWidth, height = scaledImageHeight
                };

                int scaledImageXDst = 0;
                int scaledImageYDst = 0;

                int xDstImageToRotate = (fullScreenBitmap.Width - scaledImageXDst) / 2;
                int yDstImageToRotate = (fullScreenBitmap.Height - scaledImageYDst) / 2;

                int numberOfRotations = 100;
                int degreesIncrement  = 1;
                int dynamicIncrease   = 0;
                for (int iCounter = 0; iCounter < numberOfRotations; iCounter++)
                {
                    fullScreenBitmap.Clear();
                    // Rotate and stretch
                    fullScreenBitmap.RotateImage(degreesIncrement, outputRectangle.x, outputRectangle.y, scaledImage, scaledImageXDst, scaledImageYDst, outputRectangle.width, outputRectangle.height, 0xFFFF);

                    InformationBar.DrawInformationBar(fullScreenBitmap, DisplayFont, InfoBarPosition.bottom, $"Rotate Image degrees {degreesIncrement:D3}");
                    fullScreenBitmap.Flush();

                    if (iCounter < 50)
                    {
                        degreesIncrement += dynamicIncrease;
                    }
                    else if (iCounter == 50)
                    {
                        degreesIncrement = 0;
                        dynamicIncrease  = 1;
                    }
                    else
                    {
                        degreesIncrement -= dynamicIncrease;
                    }
                    dynamicIncrease += 1;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Caught exception: " + e.Message);
            }
            finally
            {
                if (waterFall != null)
                {
                    waterFall.Dispose();
                }


                System.Threading.Thread.Sleep(500);
            }
        }
        public RotateImage(Bitmap fullScreenBitmap, Font DisplayFont)
        {
            Bitmap bmpSrc = null;
            Bitmap bmpDst = null;

            try
            {
                bmpSrc = new Bitmap(WaterFallJpg.WaterFall, Bitmap.BitmapImageType.Jpeg);
                fullScreenBitmap.StretchImage(0, 0, bmpSrc, bmpSrc.Width, bmpSrc.Height, 0x0100);
                fullScreenBitmap.Flush();

                int xDst = 0;
                int yDst = 0;

                int rotation = 0;
                for (int i = 0; i < 66; ++i)
                {
                    switch (rotation)
                    {
                    case 0:
                        xDst = (fullScreenBitmap.Width - bmpSrc.Width) / 2;
                        yDst = (fullScreenBitmap.Height - bmpSrc.Height) / 2;
                        break;

                    case 90:
                        xDst = (fullScreenBitmap.Height - bmpSrc.Height) / 2;
                        yDst = (fullScreenBitmap.Width - bmpSrc.Width) / 2;
                        break;

                    case 180:
                        xDst = (fullScreenBitmap.Width - bmpSrc.Width) / 2;
                        yDst = (fullScreenBitmap.Height - bmpSrc.Height) / 2;
                        break;

                    case 270:
                        xDst = (fullScreenBitmap.Width - bmpSrc.Width) / 2;
                        yDst = (fullScreenBitmap.Height - bmpSrc.Height) / 2;
                        break;
                    }

                    fullScreenBitmap.Clear();
                    fullScreenBitmap.RotateImage(rotation, xDst, yDst, bmpSrc, 0, 0, bmpSrc.Width, bmpSrc.Height, 0xFFFF);

                    InformationBar.DrawInformationBar(fullScreenBitmap, DisplayFont, InfoBarPosition.bottom, $"Rotate Image degrees {i:D3}");
                    fullScreenBitmap.Flush();

                    rotation += 90;
                    if (rotation == 360)
                    {
                        rotation = 0;
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Caught exception: " + e.Message);
            }
            finally
            {
                if (bmpSrc != null)
                {
                    bmpSrc.Dispose();
                }
                if (bmpDst != null)
                {
                    bmpDst.Dispose();
                }
                System.Threading.Thread.Sleep(500);
            }
        }