public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
- return sourceType == typeof(byte[]);
+ return sourceType == typeof(byte[]) || sourceType == typeof(Icon);
}
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
+ if (value is Icon icon)
+ {
+ return icon.ToBitmap();
+ }
+
if (value is byte[] bytes)
{
Debug.Assert(value != null, "value is null.");
<ProjectGuid>{AC1A1515-70D8-42E4-9B19-A72F739E974C}</ProjectGuid>
<Configurations>netcoreapp-Windows_NT-Debug;netcoreapp-Windows_NT-Release;netfx-Windows_NT-Debug;netfx-Windows_NT-Release</Configurations>
<SystemComponentmodelTypeconverterTestdataVersion>1.0.1</SystemComponentmodelTypeconverterTestdataVersion>
+ <SystemDrawingCommonTestdataVersion>1.0.9</SystemDrawingCommonTestdataVersion>
<SystemWindowsExtensionsTestdataVersion>1.0.2</SystemWindowsExtensionsTestdataVersion>
</PropertyGroup>
<ItemGroup Condition="'$(TargetsWindows)' == 'true'">
<SupplementalTestData Include="$(NuGetPackageRoot)system.componentmodel.typeconverter.testdata\$(SystemComponentmodelTypeconverterTestdataVersion)\content\**\*.*">
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
</SupplementalTestData>
+ <SupplementalTestData Include="$(NuGetPackageRoot)system.drawing.common.testdata\$(SystemDrawingCommonTestdataVersion)\content\**\*.*">
+ <Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
+ </SupplementalTestData>
<SupplementalTestData Include="$(NuGetPackageRoot)system.windows.extensions.testdata\$(SystemWindowsExtensionsTestdataVersion)\content\**\*.*">
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
</SupplementalTestData>
_imgConvFrmTD = (ImageConverter)TypeDescriptor.GetConverter(_image);
}
+ [ConditionalTheory(Helpers.IsDrawingSupported)]
+ [InlineData("48x48_multiple_entries_4bit.ico")]
+ [InlineData("256x256_seven_entries_multiple_bits.ico")]
+ [InlineData("pngwithheight_icon.ico")]
+ public void ImageConverterFromIconTest(string name)
+ {
+ using (var icon = new Icon(Helpers.GetTestBitmapPath(name)))
+ {
+ Bitmap IconBitmap = (Bitmap)_imgConv.ConvertFrom(icon);
+ Assert.NotNull(IconBitmap);
+ Assert.Equal(32, IconBitmap.Width);
+ Assert.Equal(32, IconBitmap.Height);
+ Assert.Equal(new Size(32, 32), IconBitmap.Size);
+ }
+ }
+
[ConditionalFact(Helpers.IsDrawingSupported)]
public void ImageWithOleHeader()
{
Assert.True(_imgConv.CanConvertFrom(typeof(byte[])), "byte[] (no context)");
Assert.True(_imgConv.CanConvertFrom(null, typeof(byte[])), "byte[]");
Assert.True(_imgConv.CanConvertFrom(null, _imageBytes.GetType()), "_imageBytes.GetType()");
+ Assert.True(_imgConv.CanConvertFrom(typeof(Icon)), "Icon (no context)");
+ Assert.True(_imgConv.CanConvertFrom(null, typeof(Icon)), "Icon");
Assert.False(_imgConv.CanConvertFrom(null, typeof(string)), "string");
Assert.False(_imgConv.CanConvertFrom(null, typeof(Rectangle)), "Rectangle");
Assert.False(_imgConv.CanConvertFrom(null, typeof(Point)), "Point");