Skip to content

System.Drawing.Image.FromStream is not populating PropertyItems #46411

@Socolin

Description

@Socolin

Image.FromStream is not populating PropertyItems, while Image.FromFile do that

Repro

        private static void Main()
        {
            var webClient = new WebClient();
            var imageUrl = "https://raw.githubusercontent.com/ianare/exif-samples/master/jpg/Canon_40D.jpg";
            webClient.DownloadFile(imageUrl, "1.jpg");
            var imageFromFile = Image.FromFile("1.jpg");

            Console.WriteLine("From File");
            Console.WriteLine("  w/h: " + imageFromFile.Width + " " + imageFromFile.Height);
            Console.WriteLine("  Properties: " + imageFromFile.PropertyItems.Length);
            Console.WriteLine("  PropertiesIds: " + imageFromFile.PropertyIdList.Length);


            var imageFromStream = Image.FromStream(webClient.OpenRead(imageUrl));
            Console.WriteLine("From File");
            Console.WriteLine("  w/h: " + imageFromStream.Width + " " + imageFromStream.Height);
            Console.WriteLine("  Properties: " + imageFromStream.PropertyItems.Length);
            Console.WriteLine("  PropertiesIds: " + imageFromStream.PropertyIdList.Length);
        }

Output

From File
  w/h: 100 68
  Properties: 46
  PropertiesIds: 46
From File
  w/h: 100 68
  Properties: 0
  PropertiesIds: 0

csproj

<Project Sdk="Microsoft.NET.Sdk">

	<PropertyGroup>
		<OutputType>Exe</OutputType>
		<TargetFramework>net5.0</TargetFramework>
	</PropertyGroup>

	<ItemGroup>
	  <PackageReference Include="System.Drawing.Common" Version="5.0.0" />
	</ItemGroup>

</Project>

dotnet info

.NET SDK (reflecting any global.json):
 Version:   5.0.101
 Commit:    d05174dc5a

Runtime Environment:
 OS Name:     ubuntu
 OS Version:  20.04
 OS Platform: Linux
 RID:         ubuntu.20.04-x64
 Base Path:   /usr/share/dotnet/sdk/5.0.101/

Host (useful for support):
  Version: 5.0.1
  Commit:  b02e13abab

.NET SDKs installed:
  3.1.404 [/usr/share/dotnet/sdk]
  5.0.101 [/usr/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 3.1.10 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.1 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.1.10 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.1 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET runtimes or SDKs:
  https://aka.ms/dotnet-download

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions