ImageUtility 1.4.1

.NET Framework 4.5.2
NuGet\Install-Package ImageUtility -Version 1.4.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
dotnet add package ImageUtility --version 1.4.1
<PackageReference Include="ImageUtility" Version="1.4.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ImageUtility --version 1.4.1
#r "nuget: ImageUtility, 1.4.1"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install ImageUtility as a Cake Addin
#addin nuget:?package=ImageUtility&version=1.4.1

// Install ImageUtility as a Cake Tool
#tool nuget:?package=ImageUtility&version=1.4.1
public partial class ImageUtilityTester : Form
{
    public ImageUtilityTester()
    {
        Action<string> progress = (v) => { Console.WriteLine(v); };

        //Show dialog modeless
        //if reuse FloatingImageViewer, use Show(). if use Show(true) FloatingImageViewer is disposed when closing.
        FloatingImageViewer floatingImageViewer = new FloatingImageViewer("Image", null, 0.3)
        {
            TopMost = true,
            Size = new Size(400, 400),
        };
        floatingImageViewer.ToolStripButtonPrev.Visible = floatingImageViewer.ToolStripButtonNext.Visible = false;

        ListBox lb = new ListBox() { Parent = this, Dock = DockStyle.Top, Height = 300, };
        lb.SelectedIndexChanged += (sender, e) =>
        {
            floatingImageViewer.Reset(lb.Text);
            floatingImageViewer.Title = lb.Text;
        };

        lb.ContextMenuStrip = new ContextMenuStrip();
        ToolStripMenuItem tsmiFloatingImageViewer = new ToolStripMenuItem() { Text = "Show", };
        lb.ContextMenuStrip.Items.Add(tsmiFloatingImageViewer);
        tsmiFloatingImageViewer.Click += (sender, e) =>
        {
            //if reuse FloatingImageViewer, use Show(). if use Show(true) FloatingImageViewer is disposed when closing.
            floatingImageViewer.Show();
        };

        //progress is nullable
        PictureBoxEx pictureBoxEx = new PictureBoxEx(progress, 1.0)
        {
            Height = 400
        };

        ToolStripMenuItem toolStripMenuItemDispCurrentRect = new ToolStripMenuItem() { Text = "CurrentRect", };
        toolStripMenuItemDispCurrentRect.Click += (sender, e) =>
        {
            MessageBox.Show(pictureBoxEx.CurrentRect.ToString());
        };
        pictureBoxEx.ContextMenuStrip.Items.Add(toolStripMenuItemDispCurrentRect);

        ToolStripMenuItem toolStripMenuItemDrawRect = new ToolStripMenuItem() { Text = "DrawRect parmanently", };
        toolStripMenuItemDrawRect.Click += (sender, e) =>            
        {
            pictureBoxEx.DrawRect(pictureBoxEx.CurrentRect);
        };
        pictureBoxEx.ContextMenuStrip.Items.Add(toolStripMenuItemDrawRect);

        ToolStripMenuItem toolStripMenuItemDrawString = new ToolStripMenuItem() { Text = "DrawString parmanently", };
        toolStripMenuItemDrawString.Click += (sender, e) =>
        {
            pictureBoxEx.DrawString(DateTime.Today.ToString(), pictureBoxEx.CurrentRect,true,SystemInformation.MenuFont);
        };
        pictureBoxEx.ContextMenuStrip.Items.Add(toolStripMenuItemDrawString);



        Controls.Add(pictureBoxEx.Panel);

        Controls.Add(pictureBoxEx.ToolStrip);
        var binaryImages = new List<byte[]>();

        var imageidx = 0;
        var toolStripMenuItemMultipleImages = new ToolStripMenuItem() { Text = "Multiple images", };

        Action resetImage = () =>
        {
            pictureBoxEx.ResetImage(binaryImages[imageidx]);
            pictureBoxEx.ToolStripButtonPrev.Enabled = imageidx != 0;
            pictureBoxEx.ToolStripButtonNext.Enabled = imageidx != binaryImages.Count - 1;
        };

        Action SelectFiles = () =>
        {
            binaryImages.Clear();
            var files = ImageHelper.ShowMultipleFileSelectDialog();
            foreach (var f in files)
            {
                using (System.IO.FileStream fs = new System.IO.FileStream(f, System.IO.FileMode.Open, System.IO.FileAccess.Read))
                {
                    var data = new byte[fs.Length];
                    fs.Read(data, 0, data.Length);
                    if (ImageHelper.IsImage(data))
                    {
                        binaryImages.Add(data);
                    }
                }
            }
        };

        toolStripMenuItemMultipleImages.Click += (sender, e) =>
        {
            SelectFiles();

            if (binaryImages.Count > 0)
            {
                imageidx = 0;
                resetImage();
            }
        };

        pictureBoxEx.ToolStripButtonPrev.Click += (sender, e) =>
          {
              if (imageidx > 0)
              {
                  imageidx--;
                  resetImage();
              }
          };

        pictureBoxEx.ToolStripButtonNext.Click += (sender, e) =>
          {
              if (imageidx < binaryImages.Count - 1)
              {
                  imageidx++;
                  resetImage();
              }
          };

        pictureBoxEx.ToolStripMenuItemFile.DropDownItems.Add(new ToolStripSeparator());
        pictureBoxEx.ToolStripMenuItemFile.DropDownItems.Add(toolStripMenuItemMultipleImages);

        //if move magnification menu to toolStrip enable below
        //pictureBoxEx.ToolStrip.Items.Add(pictureBoxEx.ToolStripMenuItemMagnification);
        //if move rotate menu to toolStrip enable below
        //pictureBoxEx.ToolStrip.Items.Add(pictureBoxEx.ToolStripMenuItemRotate);

        Controls.Add(pictureBoxEx.ToolStrip);
        Controls.Add(pictureBoxEx.Menu);

        var toolStripMenuItemShowImageDialog = new ToolStripMenuItem() { Text = "ImageViewer", };
        pictureBoxEx.ToolStripMenuItemFile.DropDownItems.Add(new ToolStripSeparator());
        pictureBoxEx.ToolStripMenuItemFile.DropDownItems.Add(toolStripMenuItemShowImageDialog);

        toolStripMenuItemShowImageDialog.Click += (sender, e) =>
        {
            SelectFiles();
            if (binaryImages.Count > 0)
            {
                ImageViewer.ShowDialog(binaryImages, 1.0);
                ImageViewer.ShowDialog(ImageHelper.ToImage(binaryImages.First()), 0.5);
            }
        };

        var toolStripMenuItemShowImage = new ToolStripMenuItem() { Text = "FloatingImageViewer", };
        pictureBoxEx.ToolStripMenuItemFile.DropDownItems.Add(toolStripMenuItemShowImage);

        var toolStripMenuItemShowImage2 = new ToolStripMenuItem() { Text = "FloatingImageViewer(open multiple at the same time)", };
        pictureBoxEx.ToolStripMenuItemFile.DropDownItems.Add(toolStripMenuItemShowImage2);

        toolStripMenuItemShowImage2.Click += (sender, e) =>
        {
            var files = ImageHelper.ShowMultipleFileSelectDialog();
            if (files.Length > 0)
            {
                foreach (var file in files)
                {
                    var fiv = new FloatingImageViewer("test", null, 0.3);
                    fiv.Reset(file);
                    /** if FloatingImageViewer is locally declared, set disposeWhenClosing to true to dispose when closing */
                    fiv.Show(true);
                }
            }
        };

        toolStripMenuItemShowImage.Click += (sender, e) =>
        {
            var files = ImageHelper.ShowMultipleFileSelectDialog();
            if (files.Length > 0)
            {
                lb.Items.Clear();
                lb.Items.AddRange(files);
                if (lb.Items.Count > 0)
                {
                    floatingImageViewer.Reset(lb.Items[0].ToString());
                    floatingImageViewer.Title = lb.Items[0].ToString();
                }

                //if reuse FloatingImageViewer, use Show(). if use Show(true) FloatingImageViewer is disposed when closing.
                floatingImageViewer.Show();
            }
        };

        StartPosition = FormStartPosition.CenterScreen;
        ClientSize = new Size(800, 600);
    }
}
Product Versions
.NET Framework net452 net46 net461 net462 net463 net47 net471 net472 net48
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.4.1 40 9/22/2022
1.4.0 64 9/10/2022
1.3.9.1 66 8/28/2022
1.3.9 89 7/21/2022
1.3.8 86 7/19/2022
1.3.7 111 7/17/2022
1.3.6 79 7/7/2022
1.3.5 110 6/21/2022
1.3.4 100 5/22/2022
1.3.2 121 3/26/2022
1.3.1 94 3/20/2022
1.3.0 92 3/16/2022
1.2.7 102 3/15/2022
1.2.6 96 3/13/2022
1.2.2 92 3/6/2022
1.2.1 98 3/5/2022
1.2.0 106 2/8/2022
1.1.9 104 2/7/2022
1.1.8 113 2/6/2022
1.1.7 116 1/29/2022
1.1.5 144 12/14/2021
1.1.4 137 12/8/2021
1.1.3 143 12/7/2021
1.1.1 178 11/3/2021
1.0.8 173 10/20/2021