Пример #1
0
 private void CreateIndexedImage()
 {
     IndexedBitmap   = BitmapExtensions.LoadBitmap(Filename);
     OriginalPalette = IndexedBitmap.Palette;
     Width           = IndexedBitmap.Width;
     Height          = IndexedBitmap.Height;
 }
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if ((values != null) &&
                (values.Length == 3) &&
                (values[0] is EffectsManager effectManager) &&
                (values[1] is WColor startColor) &&
                (values[2] is WColor stopColor))
            {
                var c1     = new SXColor(startColor.R, startColor.G, startColor.B, startColor.A);
                var c2     = new SXColor(stopColor.R, stopColor.G, stopColor.B, stopColor.A);
                var stream = BitmapExtensions.CreateLinearGradientBitmapStream(effectManager,
                                                                               128,
                                                                               128,
                                                                               Direct2DImageFormat.Bmp,
                                                                               new Vector2(0, 0),
                                                                               new Vector2(0, 128),
                                                                               new SharpDX.Direct2D1.GradientStop[]
                {
                    new SharpDX.Direct2D1.GradientStop()
                    {
                        Color = c1, Position = 0f
                    },
                    new SharpDX.Direct2D1.GradientStop()
                    {
                        Color = c2, Position = 1f
                    }
                });

                return(new TextureModel(stream));
            }
            else
            {
                throw new ArgumentException();
            }
        }
Пример #3
0
        public void FromBitmapTest()
        {
            foreach (int bitsPerPixel in new int[] { 1, 4, 8, 24, 32 })
            {
                foreach (bool whiteOnBlack in new bool[] { true, false })
                {
                    using (System.Drawing.Bitmap bitmap = BitmapHelpers.CreateBitmap(20, 35, bitsPerPixel, whiteOnBlack))
                    {
                        bitmap.SetResolution(252, 345);
                        BitmapHelpers.SetPixel(bitmap, 1, 1, whiteOnBlack);
                        BitmapHelpers.SetPixel(bitmap, 18, 33, whiteOnBlack);

                        Image image = BitmapExtensions.FromBitmap(bitmap);
                        Assert.AreEqual(20, image.Width);
                        Assert.AreEqual(35, image.Height);
                        Assert.AreEqual(bitsPerPixel, image.BitsPerPixel);
                        Assert.AreEqual(252, image.HorizontalResolution);
                        Assert.AreEqual(345, image.VerticalResolution);

                        uint color = bitsPerPixel == 1 ? 1u : 0u;
                        Assert.AreEqual(color, image.GetPixel(1, 1));
                        Assert.AreEqual(color, image.GetPixel(18, 33));
                    }
                }
            }
        }
Пример #4
0
        public BlueBananaPage()
        {
            Title = "Blue Banana";

            // Load banana matte bitmap (black on transparent)
            SKBitmap matteBitmap = BitmapExtensions.LoadBitmapResource(
                typeof(BlueBananaPage),
                "SkiaSharpFormsDemos.Media.BananaMatte.png");

            // Create a bitmap with a solid blue banana and transparent otherwise
            blueBananaBitmap = new SKBitmap(matteBitmap.Width, matteBitmap.Height);

            using (SKCanvas canvas = new SKCanvas(blueBananaBitmap))
            {
                canvas.Clear();
                canvas.DrawBitmap(matteBitmap, new SKPoint(0, 0));

                using (SKPaint paint = new SKPaint())
                {
                    paint.Color     = SKColors.Blue;
                    paint.BlendMode = SKBlendMode.SrcIn;
                    canvas.DrawPaint(paint);
                }
            }

            SKCanvasView canvasView = new SKCanvasView();

            canvasView.PaintSurface += OnCanvasViewPaintSurface;
            Content = canvasView;
        }
        private async void ImageCropper_ImageSaving(object sender, ImageSavingEventArgs args)
        {
            var x = args.Stream;

            App.CroppedPhotoStream = x;
            args.Cancel            = true;

            var bitmap         = BitmapExtensions.LoadBitmapStream(x);
            var ImgHeight      = bitmap.Height;
            var ImgWidth       = bitmap.Width;
            var requiredHeight = 600;
            var reqiredWidth   = ImgWidth;

            if (ImgHeight > requiredHeight)
            {
                var resizePercentage = (ImgHeight - requiredHeight) * 100 / ImgHeight;
                reqiredWidth = ImgWidth - (resizePercentage * ImgWidth / 100);
            }

            var dstInfo      = new SKImageInfo(reqiredWidth, requiredHeight);
            var uploadbitMap = bitmap.Resize(dstInfo, SKBitmapResizeMethod.Box);

            App.CroppedPhotoBitMap = uploadbitMap;
            await Navigation.PopAsync(true);

            return;
        }
Пример #6
0
        private Bitmap Draw()
        {
            Bitmap   bmp = BitmapExtensions.CreateBitmap(Program.ScreenWidth * Program.Scale, 16 * Program.Scale);
            Graphics gfx = Graphics.FromImage(bmp);

            gfx.ScaleTransform(Program.Scale, Program.Scale);
            gfx.FillRectangle(Brushes.Gray, 0, 0, Program.ScreenWidth, 16);
            Font         f      = new Font("Arial", 12);
            StringFormat format = new StringFormat();

            format.Alignment = StringAlignment.Center;
            gfx.DrawString(Text, f, Brushes.Black, Program.ScreenWidth / 2, 0, format);

            gfx.ScaleTransform(1.0f / Program.Scale, 1.0f / Program.Scale);
            string continueText = "Press R to continue";

            if (Text != "you win")
            {
                continueText = "Press R to try again";
            }

            format.Alignment = StringAlignment.Far;
            gfx.DrawString(continueText, f, Brushes.Black, Program.ScreenWidth * Program.Scale, 16, format);

            return(bmp);
        }
Пример #7
0
        public bool RecalculateCenter(double threshold = 0.0d)
        {
            SKColor updatedCenter;

            if (Colors.Count > 0)
            {
                float r = 0, g = 0, b = 0;
                foreach (SKColor color in Colors)
                {
                    r += color.Red;
                    g += color.Green;
                    b += color.Blue;
                }

                updatedCenter = new SKColor((byte)Math.Round(r / Colors.Count), (byte)Math.Round(g / Colors.Count), (byte)Math.Round(b / Colors.Count));
            }
            else
            {
                updatedCenter = new SKColor(0, 0, 0);
            }

            double distance = BitmapExtensions.EuclideanDistance(Center, updatedCenter);

            Center = updatedCenter;

            PriorCount = Colors.Count;
            Colors.Clear();

            return(distance > threshold);
        }
Пример #8
0
 public static List <Image> GetTransforms(Image img)
 {
     if (img.IsResized() || img.Data == null)
     {
         return(null);
     }
     else
     {
         List <Image> ret = new List <Image>();
         Devices.ForEach(dv =>
         {
             if (dv.IsEligible() && !dv.IsDefault)
             {
                 //device size is smaller, then image needs to be resized to fit it
                 Image retimg        = (new Image()).Clone();
                 Bitmap bmp          = BitmapExtensions.ToBitmap(img.Data);
                 Bitmap retBmp       = dv.Transform(bmp);
                 retimg.Data         = BitmapExtensions.ToBytes(retBmp);
                 retimg.Width        = retBmp.Width;
                 retimg.Height       = retBmp.Height;
                 retimg.Category     = img.Category;
                 retimg.Name         = img.Name + "-" + dv.ShortName;
                 retimg.Extension    = img.Extension;
                 retimg.ResizeDevice = dv.ID;
                 retimg.TargetDevice = GetDefault().ID;
                 retimg.URL          = retimg.GetFileURL();
                 retimg.CreationTime = DateTime.Now;
                 ret.Add(retimg);
             }
         });
         return(ret);
     }
 }
        public void PopulateResults()
        {
            // Black Spots
            double percentage = 0.0d;

            if (!_isHealthy)
            {
                percentage = System.Math.Round(_imageManagerService.GetDiseasePercentage(_healthSelectedBitmap, _blackSpotsPipeline.ResultImage), 2);
                DiseasesCollection[0].ImgSource = BitmapExtensions.GetImageFromBitmap(_blackSpotsPipeline.ResultImage).Source;
            }
            else
            {
                DiseasesCollection[0].ImgSource = BitmapExtensions.GetImageFromBitmap(_imageManagerService.HealthSelectionImageBitmap).Source;
            }

            if (percentage < 10.0)
            {
                DiseasesCollection[0].DiseaseResult = DiseaseResultType.Ok;
                DiseasesCollection[0].Details       = "Your plant is in a good state.\nPrevention for black spots disease:\n1. Baking soda spray\n2. Neem oil\n3. Sulfur";
            }
            else if (percentage > 10.0 && percentage < 20.0)
            {
                DiseasesCollection[0].DiseaseResult = DiseaseResultType.Warning;
                DiseasesCollection[0].Details       = "Your plant seems to become affected by black spots disease.\n1. Provide good air circulation around and through your plant\n2. Remove any infected leaves.\n";
            }
            else if (percentage > 20.0)
            {
                DiseasesCollection[0].DiseaseResult = DiseaseResultType.Error;
                DiseasesCollection[0].Details       = "Your plant is seriously affected. You need to be very careful!\n1. Provide good air circulation around and through your plant\n2. Avoid getting the leaves wet while watering.\n3. Remove any infected leaves.";
            }
            DiseasesCollection[0].Percentage = "Severity:\n" + percentage + "%";

            // Refresh Diseases GUI
            DiseasesCollection = new ObservableCollection <DiseaseInfo>(DiseasesCollection);
        }
Пример #10
0
        private static string AddNewFile(string path, Guid libraryId, GameDatabase database)
        {
            var          fileName = Guid.NewGuid().ToString() + Path.GetExtension(path);
            var          fileId   = $"{libraryId.ToString()}/{fileName}";
            MetadataFile metaFile = null;

            try
            {
                if (path.StartsWith("http", StringComparison.OrdinalIgnoreCase))
                {
                    metaFile = new MetadataFile(fileId, fileName, HttpDownloader.DownloadData(path));
                }
                else
                {
                    if (File.Exists(path))
                    {
                        if (path.EndsWith(".exe", StringComparison.OrdinalIgnoreCase))
                        {
                            var icon = IconExtension.ExtractIconFromExe(path, true);
                            if (icon == null)
                            {
                                return(null);
                            }

                            fileName = Path.ChangeExtension(fileName, ".png");
                            fileId   = Path.ChangeExtension(fileId, ".png");
                            metaFile = new MetadataFile(fileId, fileName, icon.ToByteArray(System.Drawing.Imaging.ImageFormat.Png));
                        }
                        else
                        {
                            metaFile = new MetadataFile(fileId, fileName, File.ReadAllBytes(path));
                        }
                    }
                    else
                    {
                        logger.Error($"Can't add game file during game import, file doesn't exists: {path}");
                    }
                }
            }
            catch (Exception e) when(!PlayniteEnvironment.ThrowAllErrors)
            {
                logger.Error(e, $"Failed to import game file during game import from {path}");
            }

            if (metaFile != null)
            {
                if (metaFile.FileName.EndsWith(".tga", StringComparison.OrdinalIgnoreCase))
                {
                    metaFile.FileName = Path.ChangeExtension(metaFile.FileName, ".png");
                    metaFile.FileId   = Path.ChangeExtension(metaFile.FileId, ".png");
                    metaFile.Content  = BitmapExtensions.TgaToBitmap(metaFile.Content).ToPngArray();
                }

                database.AddFile(metaFile);
                return(metaFile.FileId);
            }

            return(null);
        }
Пример #11
0
            public Bitmap Transform(Bitmap bmp)
            {
                int w = bmp.Width;
                int h = bmp.Height;

                this.SetImageScale(ref w, ref h);
                return(BitmapExtensions.Scale(bmp, w, h));
            }
Пример #12
0
        public BitmapResizeView()
        {
            InitializeComponent();

            var bitmap = BitmapExtensions.LoadBitmapResource(typeof(BitmapRotateView), "SkiaSharp_Samples.Resources.Banana.jpg");

            photoCropper = new PhotoCropperCanvasView(bitmap);
            canvasViewHost.Children.Add(photoCropper);
        }
Пример #13
0
        public static void AddLargeIconToCache(string extension, byte[] imageContents)
        {
            string ext = extension.ToLower();

            if (!m_cachedLargeIcons.ContainsKey(ext))
            {
                m_cachedLargeIcons.Add(ext, BitmapExtensions.ToBitmap(imageContents));
            }
        }
Пример #14
0
        private Bitmap Draw()
        {
            Bitmap   bmp = BitmapExtensions.CreateBitmap(4, 4);
            Graphics gfx = Graphics.FromImage(bmp);

            gfx.FillEllipse(Brushes.Black, 0, 0, 4, 4);

            return(bmp);
        }
Пример #15
0
        private Bitmap Draw()
        {
            Bitmap   bmp = BitmapExtensions.CreateBitmap(16, 16);
            Graphics gfx = Graphics.FromImage(bmp);

            gfx.FillPolygon(new SolidBrush(Color), new Point[] { new Point(0, 16), new Point(8, 0), new Point(16, 16) });

            return(bmp);
        }
Пример #16
0
 public Bitmap Decode(MemoryStream EncodedStream)
 {
     EncodedStream.Position = 0;
     if (TrailBitmap == null)
     {
         byte[] Header = new byte[4];
         if (EncodedStream.CanRead)
         {
             EncodedStream.Read(Header, 0, Header.Length);
             int    ImageLength = BitConverter.ToInt32(Header, 0);
             byte[] ImageBuffer = new byte[ImageLength];
             EncodedStream.Read(ImageBuffer, 0, ImageBuffer.Length);
             TrailBitmap = (Bitmap)Image.FromStream(new MemoryStream(ImageBuffer));
         }
     }
     else
     {
         BitmapData StickData  = TrailBitmap.LockBits(new Rectangle(0, 0, TrailBitmap.Width, TrailBitmap.Height), ImageLockMode.ReadWrite, TrailBitmap.PixelFormat);
         int        Stride     = Math.Abs(StickData.Stride);
         int        DataLength = (int)EncodedStream.Length;
         byte[]     Header     = new byte[20];
         Changes.Clear();
         while (DataLength > 0)
         {
             EncodedStream.Read(Header, 0, Header.Length);
             Rectangle BlockChange = new Rectangle(BitConverter.ToInt32(Header, 0), BitConverter.ToInt32(Header, 4), BitConverter.ToInt32(Header, 8), BitConverter.ToInt32(Header, 12));
             if (IsEnableChanges)
             {
                 lock (ChangesLock)
                 {
                     Changes.Add(ScaleToViewPort(BlockChange));
                 }
             }
             int    ImageLength = BitConverter.ToInt32(Header, 16);
             byte[] ImageBuffer = new byte[ImageLength];
             EncodedStream.Read(ImageBuffer, 0, ImageBuffer.Length);
             using (MemoryStream ImgStream = new MemoryStream(ImageBuffer))
             {
                 using (Bitmap Img = (Bitmap)Image.FromStream(ImgStream))
                 {
                     int        PixelSize = BitmapExtensions.BytesPerPixel(Img.PixelFormat);
                     BitmapData ImgData   = Img.LockBits(new Rectangle(0, 0, Img.Width, Img.Height), ImageLockMode.WriteOnly, Img.PixelFormat);
                     for (int y = 0; y < BlockChange.Height; ++y)
                     {
                         int SrcOffset = Math.Abs(ImgData.Stride) * y;
                         int DstOffset = ((BlockChange.Y + y) * Stride) + (BlockChange.X * PixelSize);
                         NativeMethods.memcpy(StickData.Scan0 + DstOffset, ImgData.Scan0 + SrcOffset, (uint)(Img.Width * PixelSize));
                     }
                     Img.UnlockBits(ImgData);
                 }
             }
             DataLength -= 20 + ImageLength;
         }
         TrailBitmap.UnlockBits(StickData);
     }
     return(TrailBitmap);
 }
Пример #17
0
        private Bitmap Draw()
        {
            Bitmap   bmp = BitmapExtensions.CreateBitmap(this.Width, this.Height);
            Graphics gfx = Graphics.FromImage(bmp);

            gfx.FillRectangle(new SolidBrush(Color), 0, 0, this.Width, this.Height);

            return(bmp);
        }
Пример #18
0
        private Bitmap Draw()
        {
            Bitmap   bmp = BitmapExtensions.CreateBitmap(8, 8);
            Graphics gfx = Graphics.FromImage(bmp);

            gfx.FillEllipse(new SolidBrush(Color), 0, 0, 8, 8);

            return(bmp);
        }
Пример #19
0
        public static object GetIcon(string iconName, double imageHeight = 16, double imageWidth = 16)
        {
            if (iconName.IsNullOrEmpty())
            {
                return(null);
            }

            var resource = ResourceProvider.GetResource(iconName);

            if (resource != null)
            {
                if (resource is string stringIcon)
                {
                    return(Images.GetImageFromFile(ThemeFile.GetFilePath(stringIcon), BitmapScalingMode.Fant, imageHeight, imageWidth));
                }
                else if (resource is BitmapImage bitmap)
                {
                    var image = new System.Windows.Controls.Image()
                    {
                        Source = bitmap
                    };
                    RenderOptions.SetBitmapScalingMode(image, RenderOptions.GetBitmapScalingMode(bitmap));
                    return(image);
                }
                else if (resource is TextBlock textIcon)
                {
                    var text = new TextBlock
                    {
                        Text       = textIcon.Text,
                        FontFamily = textIcon.FontFamily,
                        FontStyle  = textIcon.FontStyle
                    };

                    if (textIcon.ReadLocalValue(TextBlock.ForegroundProperty) != DependencyProperty.UnsetValue)
                    {
                        text.Foreground = textIcon.Foreground;
                    }

                    return(text);
                }
            }
            else if (System.IO.File.Exists(iconName))
            {
                return(BitmapExtensions.BitmapFromFile(iconName)?.ToImage());
            }
            else
            {
                var themeFile = ThemeFile.GetFilePath(iconName);
                if (themeFile != null)
                {
                    return(Images.GetImageFromFile(themeFile, BitmapScalingMode.Fant, imageHeight, imageWidth));
                }
            }

            return(null);
        }
Пример #20
0
        private void ButtonSelectImage_Click(object sender, RoutedEventArgs e)
        {
            var path = Dialogs.SelectImageFile(this);

            if (!string.IsNullOrEmpty(path))
            {
                ImageImage.Source = BitmapExtensions.BitmapFromFile(path);
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(ImageImage.Tag.ToString()));
            }
        }
Пример #21
0
        public PhotoCroppingPage()
        {
            InitializeComponent();

            SKBitmap bitmap = BitmapExtensions.LoadBitmapResource(GetType(),
                                                                  "SkiaSharpFormsDemos.Media.MountainClimbers.jpg");

            photoCropper = new PhotoCropperCanvasView(bitmap);
            canvasViewHost.Children.Add(photoCropper);
        }
Пример #22
0
        public static System.Drawing.Image ToImage(List <Vector3> listOfPoints)
        {
            ushort[] myDepthFrame = FromVector3List(listOfPoints);

            byte[] pixels = ImageExtensions.ConvertUshortToByte(myDepthFrame);


            System.Drawing.Image depthImage = BitmapExtensions.FromByteArray_Gray(pixels, DepthMetaData.XDepthMaxKinect, DepthMetaData.YDepthMaxKinect);
            return(depthImage);
        }
Пример #23
0
        private Bitmap Draw()
        {
            Bitmap   bmp = BitmapExtensions.CreateBitmap(Program.ScreenWidth * Program.Scale, Program.ScreenHeight * Program.Scale);
            Graphics gfx = Graphics.FromImage(bmp);

            Font         f      = new Font("Arial", 12);
            StringFormat format = new StringFormat();

            if (Program.ShowDiags)
            {
                gfx.DrawString($"tps: {Program.Builder.tps}", f, Brushes.Black, new Point(0, Program.ScreenHeight * Program.Scale - 48), format);
                gfx.DrawString($"tick: {Program.Builder.tickTime}", f, Brushes.Black, new Point(0, Program.ScreenHeight * Program.Scale - 32), format);
                gfx.DrawString($"draw: {Program.Builder.drawTime}", f, Brushes.Black, new Point(0, Program.ScreenHeight * Program.Scale - 16), format);
            }

            format.Alignment = StringAlignment.Far;
            int i = 0;

            string timeLeft = $"Time left: {Program.Referee.Timer / Program.TPS}";

            gfx.DrawString(timeLeft, f, Brushes.Black, new Point(Program.ScreenWidth * Program.Scale, 0), format);

            gfx.DrawString($"Lives: {new string('$', Program.Lives)}", f, Brushes.Black, new Point(Program.ScreenWidth * Program.Scale, 16), format);

            format.Alignment = StringAlignment.Near;
            foreach (Stack <Rule> stack in Program.Referee.Piles.Values)
            {
                if (stack.Any())
                {
                    string name = stack.Peek().Name;
                    Rule   rule = stack.Peek();
                    string show = $"{stack.Peek().Type}: {name}";
                    float  xPos = 0;
                    foreach (string piece in show.Split(" "))
                    {
                        Color        color     = Color.Black;
                        string       classname = piece.Trim();
                        Assembly     assembly  = Assembly.GetAssembly(typeof(Program));
                        Type         t         = assembly.GetType($"Game.{classname}");
                        PropertyInfo p;
                        if (t != null && (p = t.GetProperty("Color")) != null)
                        {
                            color = (Color)p.GetValue(null);
                        }

                        gfx.DrawString(piece, f, new SolidBrush(color), new Point((int)xPos, i * 18), format);
                        xPos += gfx.MeasureString(piece, f).Width;
                    }

                    i++;
                }
            }

            return(bmp);
        }
Пример #24
0
 protected override KeyValuePair <int, TextLayoutInfo>[] GetArray(IEnumerable <TextInfoExt> items)
 {
     return(items.Select((x, i) =>
     {
         var textLayout = BitmapExtensions
                          .GetTextLayoutMetrices(x.Text, deviceRes2D, x.Size, x.FontFamily,
                                                 x.FontWeight, x.FontStyle);
         return new KeyValuePair <int, TextLayoutInfo>(i,
                                                       new TextLayoutInfo(textLayout, x.Foreground, x.Background, x.Padding));
     }).ToArray());
 }
Пример #25
0
 private void CreateStandardImage(string PaletteDataPath)
 {
     StandardBitmap = SetPaletteColors(BitmapExtensions.LoadBitmap(Filename), PaletteDataPath);
     if (StandardBitmap.Palette != null && StandardBitmap.Palette.Entries.Length > 0)
     {
         StandardBitmap.MakeTransparent(StandardBitmap.Palette.Entries[0]);
     }
     else
     {
         StandardBitmap.MakeTransparent(SystemColor.FromArgb(0xff00ff));
     }
 }
Пример #26
0
        public Bitmap Image()
        {
            if (bmp == null)
            {
                bmp = BitmapExtensions.CreateBitmap(actions.Length * 16, 16);
                gfx = Graphics.FromImage(bmp);
            }

            Sprite window           = Sprite.Sprites["window"];
            Brush  transparentBlack = new SolidBrush(Color.FromArgb(255 / 2, 0, 0, 0));

            gfx.DrawImage(window.GetImage(0 + 3 * window.HImages), 0, 0);
            if (actions.First() != null)
            {
                gfx.DrawImage(actions.First().Image(), 0, 0);
                Skill skill = actions.First() as Skill;
                if (skill != null)
                {
                    float percentCooldown = skill.CooldownTime * 1.0f / skill.CooldownDuration;
                    gfx.FillRectangle(transparentBlack, 0, (1 - percentCooldown) * 16, 16, percentCooldown * 16);
                }
            }

            for (int i = 1; i < actions.Length - 1; i++)
            {
                gfx.DrawImage(window.GetImage(1 + 3 * window.HImages), i * 16, 0);
                if (actions[i] != null)
                {
                    gfx.DrawImage(actions[i].Image(), i * 16, 0);
                    Skill skill = actions[i] as Skill;
                    if (skill != null)
                    {
                        float percentCooldown = skill.CooldownTime * 1.0f / skill.CooldownDuration;
                        gfx.FillRectangle(transparentBlack, i * 16, (1 - percentCooldown) * 16, 16, percentCooldown * 16);
                    }
                }
            }

            gfx.DrawImage(window.GetImage(2 + 3 * window.HImages), bmp.Width - 16, 0);
            if (actions.Last() != null)
            {
                gfx.DrawImage(actions.Last().Image(), bmp.Width - 16, 0);
                Skill skill = actions.Last() as Skill;
                if (skill != null)
                {
                    float percentCooldown = skill.CooldownTime * 1.0f / skill.CooldownDuration;
                    gfx.FillRectangle(transparentBlack, bmp.Width - 16, (1 - percentCooldown) * 16, 16, percentCooldown * 16);
                }
            }

            return(bmp);
        }
Пример #27
0
        public Bitmap Draw()
        {
            if (bmp == null)
            {
                bmp = BitmapExtensions.CreateBitmap(this.Width, this.Height);
                gfx = Graphics.FromImage(bmp);
            }

            gfx.DrawLine(Pens.Black, 1, 1, bmp.Width - 2, bmp.Height - 2);
            gfx.DrawLine(Pens.Black, bmp.Width - 2, 1, 1, bmp.Height - 2);

            return(bmp);
        }
        public PortraitView()
        {
            InitializeComponent();

            this.BindingContext = viewModel = ViewModelLocator.SlideshowViewModel;

            currentBody              = Body1;
            currentHeading           = Heading1;
            offscreenBody            = Body2;
            offscreenHeading         = Heading2;
            offscreenBody.Opacity    = 0;
            offscreenHeading.Opacity = 0;
            currentBitmap            = BitmapExtensions.LoadBitmapResource(this.GetType(), viewModel.CurrentLocation.ImageResource);
        }
Пример #29
0
        private void OpenFile(string fileName)
        {
            try
            {
                var bmp = BitmapExtensions.Load(fileName);

                pictureBox1.Image = bmp ?? throw new ApplicationException(Resources.errorLoadFailed);
                pictureBox1.Size  = bmp.Size;
            }
            catch (Exception e)
            {
                MessageBox.Show(this, e.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
Пример #30
0
        public void EncodeDefault(MemoryStream OutStream, Bitmap CurrentBitmap, Size blockSize, PixelFormat BitmapFormat)
        {
            BlockScan = blockSize;
            PixelSize = BitmapExtensions.BytesPerPixel(BitmapFormat);
            if (TrailBitmap == null)
            {
                byte[] EncodedBytes = Compressor.Compress(CurrentBitmap);
                OutStream.Write(BitConverter.GetBytes(EncodedBytes.Length), 0, 4);
                OutStream.Write(EncodedBytes, 0, EncodedBytes.Length);
                TrailBitmap = CurrentBitmap;
            }
            else
            {
                BitmapData TrailData   = TrailBitmap.LockBits(new Rectangle(0, 0, TrailBitmap.Width, TrailBitmap.Height), ImageLockMode.ReadOnly, BitmapFormat);
                BitmapData CurrentData = CurrentBitmap.LockBits(new Rectangle(0, 0, CurrentBitmap.Width, CurrentBitmap.Height), ImageLockMode.ReadOnly, BitmapFormat);
                int        Stride      = Math.Abs(TrailData.Stride);
                Task.WaitAll(new[]
                {
                    Task.Run(() => UpperProcess(0, 0, TrailData.Width, TrailData.Height / 2, Stride, TrailData.Scan0, CurrentData.Scan0)),
                    Task.Run(() => LowerProcess(0, TrailData.Height / 2, TrailData.Width, TrailData.Height, Stride, TrailData.Scan0, CurrentData.Scan0)),
                });
                CurrentBitmap.UnlockBits(CurrentData);
                TrailBitmap.UnlockBits(TrailData);

                List <Rectangle> Changes = new List <Rectangle>(UpperChanges.Count + LowerChanges.Count);
                Changes.AddRange(UpperChanges);
                Changes.AddRange(LowerChanges);

                for (int i = 0; i < Changes.Count; ++i)
                {
                    Rectangle Change = Changes[i];
                    OutStream.Write(BitConverter.GetBytes(Change.X), 0, 4);
                    OutStream.Write(BitConverter.GetBytes(Change.Y), 0, 4);
                    OutStream.Write(BitConverter.GetBytes(Change.Width), 0, 4);
                    OutStream.Write(BitConverter.GetBytes(Change.Height), 0, 4);
                    CurrentData = CurrentBitmap.LockBits(new Rectangle(Change.X, Change.Y, Change.Width, Change.Height), ImageLockMode.ReadOnly, BitmapFormat);
                    using (Bitmap ChangedBmp = new Bitmap(Change.Width, Change.Height, CurrentData.Stride, BitmapFormat, CurrentData.Scan0))
                    {
                        byte[] CompressedImage = Compressor.Compress(ChangedBmp);
                        OutStream.Write(BitConverter.GetBytes(CompressedImage.Length), 0, 4);
                        OutStream.Write(CompressedImage, 0, CompressedImage.Length);
                    }
                    CurrentBitmap.UnlockBits(CurrentData);
                }
                TrailBitmap.Dispose();
                TrailBitmap = CurrentBitmap;
                ClearChanges();
            }
        }