Skip to content

Commit

Permalink
ImageVisualizer: update
Browse files Browse the repository at this point in the history
  • Loading branch information
meee1 committed Nov 4, 2020
1 parent 60c0822 commit d06c1b6
Show file tree
Hide file tree
Showing 19 changed files with 87 additions and 189 deletions.
54 changes: 2 additions & 52 deletions ExtLibs/ImageVisualizer/src/ImageVisualizer.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29721.120
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImageVisualizer10", "ImageVisualizer10\ImageVisualizer10.csproj", "{8377674C-A112-4DC9-9745-926434AE7B2E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImageVisualizer11", "ImageVisualizer11\ImageVisualizer11.csproj", "{496B16D7-54D1-418B-951B-71DD377156A7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImageVisualizer12", "ImageVisualizer12\ImageVisualizer12.csproj", "{2B4306BF-2E14-4E75-AA09-5423E906C5D8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImageVisualizer14", "ImageVisualizer14\ImageVisualizer14.csproj", "{318C7CE4-37EE-4185-945D-B7833677A29A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImageVisualizer15", "ImageVisualizer15\ImageVisualizer15.csproj", "{0A095313-31F1-4677-ACC2-60BCF5ADFC5D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImageVisualizer16.UI", "ImageVisualizer16.UI\ImageVisualizer16.UI.csproj", "{63D1D741-7C82-447B-B5F8-68B3BE3470D2}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ImageVisualizer16.Common", "ImageVisualizer16.Common\ImageVisualizer16.Common.csproj", "{B271E1B1-BB78-4864-8DB5-BC48FB1CB132}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ImageVisualizer16.DebuggeeSide", "ImageVisualizer16.DebuggeeSide\ImageVisualizer16.DebuggeeSide.csproj", "{552D4CE4-EF94-4232-B8EA-C5F26E930220}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImageVisualizerPackage", "ImageVisualizerPackage\ImageVisualizerPackage.csproj", "{FB4C20B3-659C-4D7E-9832-7BFB165DF2E0}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImageVisualizerSkiaPackage", "ImageVisualizerPackage\ImageVisualizerSkiaPackage.csproj", "{FB4C20B3-659C-4D7E-9832-7BFB165DF2E0}"
EndProject
Project("{930C7802-8A8C-48F9-8165-68863BCCD9DD}") = "SetupVisualizer", "SetupVisualizer\SetupVisualizer.wixproj", "{49BAF40F-9365-482B-BC8E-43557931B415}"
Project("{930C7802-8A8C-48F9-8165-68863BCCD9DD}") = "SetupVisualizerSkia", "SetupVisualizer\SetupVisualizerSkia.wixproj", "{49BAF40F-9365-482B-BC8E-43557931B415}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{6AE77D16-314C-4016-A4C0-016E1EEF6F80}"
ProjectSection(SolutionItems) = preProject
Expand All @@ -36,46 +26,6 @@ Global
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8377674C-A112-4DC9-9745-926434AE7B2E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8377674C-A112-4DC9-9745-926434AE7B2E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8377674C-A112-4DC9-9745-926434AE7B2E}.Debug|x86.ActiveCfg = Debug|Any CPU
{8377674C-A112-4DC9-9745-926434AE7B2E}.Debug|x86.Build.0 = Debug|Any CPU
{8377674C-A112-4DC9-9745-926434AE7B2E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8377674C-A112-4DC9-9745-926434AE7B2E}.Release|Any CPU.Build.0 = Release|Any CPU
{8377674C-A112-4DC9-9745-926434AE7B2E}.Release|x86.ActiveCfg = Release|Any CPU
{8377674C-A112-4DC9-9745-926434AE7B2E}.Release|x86.Build.0 = Release|Any CPU
{496B16D7-54D1-418B-951B-71DD377156A7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{496B16D7-54D1-418B-951B-71DD377156A7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{496B16D7-54D1-418B-951B-71DD377156A7}.Debug|x86.ActiveCfg = Debug|Any CPU
{496B16D7-54D1-418B-951B-71DD377156A7}.Debug|x86.Build.0 = Debug|Any CPU
{496B16D7-54D1-418B-951B-71DD377156A7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{496B16D7-54D1-418B-951B-71DD377156A7}.Release|Any CPU.Build.0 = Release|Any CPU
{496B16D7-54D1-418B-951B-71DD377156A7}.Release|x86.ActiveCfg = Release|Any CPU
{496B16D7-54D1-418B-951B-71DD377156A7}.Release|x86.Build.0 = Release|Any CPU
{2B4306BF-2E14-4E75-AA09-5423E906C5D8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2B4306BF-2E14-4E75-AA09-5423E906C5D8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2B4306BF-2E14-4E75-AA09-5423E906C5D8}.Debug|x86.ActiveCfg = Debug|Any CPU
{2B4306BF-2E14-4E75-AA09-5423E906C5D8}.Debug|x86.Build.0 = Debug|Any CPU
{2B4306BF-2E14-4E75-AA09-5423E906C5D8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2B4306BF-2E14-4E75-AA09-5423E906C5D8}.Release|Any CPU.Build.0 = Release|Any CPU
{2B4306BF-2E14-4E75-AA09-5423E906C5D8}.Release|x86.ActiveCfg = Release|Any CPU
{2B4306BF-2E14-4E75-AA09-5423E906C5D8}.Release|x86.Build.0 = Release|Any CPU
{318C7CE4-37EE-4185-945D-B7833677A29A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{318C7CE4-37EE-4185-945D-B7833677A29A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{318C7CE4-37EE-4185-945D-B7833677A29A}.Debug|x86.ActiveCfg = Debug|Any CPU
{318C7CE4-37EE-4185-945D-B7833677A29A}.Debug|x86.Build.0 = Debug|Any CPU
{318C7CE4-37EE-4185-945D-B7833677A29A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{318C7CE4-37EE-4185-945D-B7833677A29A}.Release|Any CPU.Build.0 = Release|Any CPU
{318C7CE4-37EE-4185-945D-B7833677A29A}.Release|x86.ActiveCfg = Release|Any CPU
{318C7CE4-37EE-4185-945D-B7833677A29A}.Release|x86.Build.0 = Release|Any CPU
{0A095313-31F1-4677-ACC2-60BCF5ADFC5D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0A095313-31F1-4677-ACC2-60BCF5ADFC5D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0A095313-31F1-4677-ACC2-60BCF5ADFC5D}.Debug|x86.ActiveCfg = Debug|Any CPU
{0A095313-31F1-4677-ACC2-60BCF5ADFC5D}.Debug|x86.Build.0 = Debug|Any CPU
{0A095313-31F1-4677-ACC2-60BCF5ADFC5D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0A095313-31F1-4677-ACC2-60BCF5ADFC5D}.Release|Any CPU.Build.0 = Release|Any CPU
{0A095313-31F1-4677-ACC2-60BCF5ADFC5D}.Release|x86.ActiveCfg = Release|Any CPU
{0A095313-31F1-4677-ACC2-60BCF5ADFC5D}.Release|x86.Build.0 = Release|Any CPU
{63D1D741-7C82-447B-B5F8-68B3BE3470D2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{63D1D741-7C82-447B-B5F8-68B3BE3470D2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{63D1D741-7C82-447B-B5F8-68B3BE3470D2}.Debug|x86.ActiveCfg = Debug|Any CPU
Expand Down
32 changes: 15 additions & 17 deletions ExtLibs/ImageVisualizer/src/ImageVisualizer14/ImageForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 4 additions & 33 deletions ExtLibs/ImageVisualizer/src/ImageVisualizer14/ImageForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Media.Imaging;
using Microsoft.VisualStudio.DebuggerVisualizers;
using SkiaSharp;

Expand Down Expand Up @@ -77,40 +76,12 @@ public ImageForm(IVisualizerObjectProvider objectProvider)
var method = objectBitmap.GetType().GetMethod("ToBitmap", new Type[] { });
if (method != null)
{
objectBitmap = method.Invoke(objectBitmap, null);
pictureBox1.Image = (Bitmap)method.Invoke(objectBitmap, null);
}

BitmapSource bitmapSource = null;

if (objectBitmap is Bitmap)
{
var hObject = ((Bitmap)objectBitmap).GetHbitmap();

try
{
bitmapSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
hObject,
IntPtr.Zero,
Int32Rect.Empty,
BitmapSizeOptions.FromEmptyOptions());
}
catch (Win32Exception)
{
bitmapSource = null;
}
finally
{
DeleteObject(hObject);
}
}
else if (objectBitmap is SerializableBitmapImage serializableBitmapImage)
{
bitmapSource = serializableBitmapImage;
}

if (bitmapSource != null)

if (objectBitmap is SerializableBitmapImage serializableBitmapImage)
{
imageControl.SetImage(bitmapSource);
pictureBox1.Image = Image.FromStream(new MemoryStream((SerializableBitmapImage) objectBitmap));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@

[assembly: System.Diagnostics.DebuggerVisualizer(typeof(ImageVisualizer), typeof(ImageVisualizerObjectSource), Target = typeof(SKImage), Description = "SKImage Visualizer")]
[assembly: System.Diagnostics.DebuggerVisualizer(typeof(ImageVisualizer), typeof(ImageVisualizerObjectSource), Target = typeof(SKBitmap), Description = "SKBitmap Visualizer")]
[assembly: System.Diagnostics.DebuggerVisualizer(typeof(ImageVisualizer), typeof(ImageVisualizerObjectSource), Target = typeof(SKSurface), Description = "SKSurface Visualizer")]

//System.Drawing.Bitmap
[assembly: System.Diagnostics.DebuggerVisualizer(typeof(ImageVisualizer), typeof(VisualizerObjectSource), Target = typeof(System.Drawing.Bitmap), Description = "Image Visualizer")]
//System.Windows.Media.ImageSource, System.Windows.Media.Imaging.BitmapImage, System.Windows.Media.Imaging.BitmapSource
[assembly: System.Diagnostics.DebuggerVisualizer(typeof(ImageVisualizer), typeof(ImageVisualizerObjectSource), Target = typeof(System.Windows.Media.ImageSource), Description = "Image Visualizer")]

namespace Aberus.VisualStudio.Debugger.ImageVisualizer
{
Expand Down Expand Up @@ -56,6 +55,7 @@ class Program
static void Main(string[] args)
{
var image5 = new SKBitmap(1280, 720);
image5.SetPixel(5, 5, SKColors.Red);
ImageVisualizer.TestShowVisualizer(image5);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
using System.IO;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Microsoft.VisualStudio.DebuggerVisualizers;
using SkiaSharp;

namespace Aberus.VisualStudio.Debugger.ImageVisualizer
{
public class ImageVisualizerObjectSource : VisualizerObjectSource
{
/// <summary>
/// Grab the source, and return a png stream
/// </summary>
/// <param name="target"></param>
/// <param name="outgoingData"></param>
public override void GetData(object target, Stream outgoingData)
{
if (target is SKBitmap image1)
{
var bitmapSource = PngBitmapDecoder.Create(image1.Encode(SKEncodedImageFormat.Png, 100).AsStream(),
BitmapCreateOptions.None,
BitmapCacheOption.Default);
base.GetData(new SerializableBitmapImage(bitmapSource.Frames[0]), outgoingData);
var bitmapSource = image1.Encode(SKEncodedImageFormat.Png, 100).AsStream();
base.GetData(new SerializableBitmapImage(bitmapSource), outgoingData);
}
else if (target is SKImage image2)
{
var bitmapSource = PngBitmapDecoder.Create(image2.Encode().AsStream(), BitmapCreateOptions.None,
BitmapCacheOption.Default).Frames[0];
var bitmapSource = image2.Encode(SKEncodedImageFormat.Png, 100).AsStream();
base.GetData(new SerializableBitmapImage(bitmapSource), outgoingData);
}
else if (target is ImageSource image3)
else if (target is SKSurface image3)
{
base.GetData(new SerializableBitmapImage((BitmapSource) image3), outgoingData);
base.GetData(
new SerializableBitmapImage(image3.Snapshot().Encode(SKEncodedImageFormat.Png, 100).AsStream()),
outgoingData);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.8.0.0")]
[assembly: AssemblyVersion("0.8.0")]
[assembly: AssemblyFileVersion("0.8.0.0")]
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,24 @@
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Windows.Media.Imaging;

namespace Aberus.VisualStudio.Debugger.ImageVisualizer
{
[Serializable]
public class SerializableBitmapImage : ISerializable
{
public BitmapSource bitmapSource;
private readonly string expression;
public byte[] Image { get; private set; }

public BitmapImage Image { get; private set; }

public SerializableBitmapImage(BitmapImage image)
public SerializableBitmapImage(byte[] image)
{
this.Image = image;
}

public SerializableBitmapImage(BitmapSource source)
public SerializableBitmapImage(Stream image)
{
bitmapSource = source;
var ms = new MemoryStream();
image.CopyTo(ms);
this.Image = ms.ToArray();
}

protected SerializableBitmapImage(SerializationInfo info, StreamingContext context)
Expand All @@ -34,15 +32,7 @@ protected SerializableBitmapImage(SerializationInfo info, StreamingContext conte
{
if (i.Value is byte[] array)
{
var stream = new MemoryStream(array);
stream.Seek(0, SeekOrigin.Begin);

Image = new BitmapImage();
Image.CacheOption = BitmapCacheOption.OnLoad;
Image.BeginInit();
Image.StreamSource = stream;
Image.EndInit();
Image.Freeze();
Image = (byte[])i.Value;
}
}
catch (ExternalException)
Expand All @@ -66,47 +56,35 @@ protected SerializableBitmapImage(SerializationInfo info, StreamingContext conte
}
else if(string.Equals(i.Name, "Name", StringComparison.OrdinalIgnoreCase))
{
expression = (string)i.Value;

}
}
}

public static implicit operator SerializableBitmapImage(BitmapImage bitmapImage)
public static implicit operator SerializableBitmapImage(byte[] bitmapImage)
{
return new SerializableBitmapImage(bitmapImage);
}

public static implicit operator BitmapImage(SerializableBitmapImage serializableBitmapImage)
public static implicit operator byte[](SerializableBitmapImage serializableBitmapImage)
{
return serializableBitmapImage.Image;
}

//[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)]
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
{
var source = Image ?? bitmapSource;

if (source != null)
{
using (var memoryStream = new MemoryStream())
{
var encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(source));
encoder.Save(memoryStream);
memoryStream.Seek(0, SeekOrigin.Begin);

info.AddValue("Image", memoryStream.ToArray(), typeof(byte[]));
info.AddValue("Image", Image, typeof(byte[]));
}

info.AddValue("Name", source.ToString());
info.AddValue("Name", "Names");
}
}

public override string ToString()
{
if (!string.IsNullOrEmpty(expression))
return expression;

return base.ToString();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.0;net461</TargetFrameworks>
<TargetFrameworks>net461;netstandard2.0;netcoreapp2.0</TargetFrameworks>
<RootNamespace>Aberus.VisualStudio.Debugger.ImageVisualizer</RootNamespace>
<UseWPF>true</UseWPF>

<AssemblyName>Aberus.VisualStudio.Debugger.ImageVisualizer.Common</AssemblyName>
</PropertyGroup>

Expand Down
Loading

0 comments on commit d06c1b6

Please sign in to comment.