Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean-up System.Drawing.Common and remove the Unix code. #64623

Merged
merged 16 commits into from
Apr 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
164 changes: 50 additions & 114 deletions src/libraries/System.Drawing.Common/src/System.Drawing.Common.csproj

Large diffs are not rendered by default.

This file was deleted.

This file was deleted.

38 changes: 34 additions & 4 deletions src/libraries/System.Drawing.Common/src/System/Drawing/Bitmap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.ComponentModel;
using System.Drawing.Imaging;
using System.Drawing.Internal;
using System.IO;
using System.Runtime.InteropServices;
using Gdip = System.Drawing.SafeNativeMethods.Gdip;
Expand All @@ -14,7 +15,7 @@ namespace System.Drawing
"System.Drawing.Design.UITypeEditor, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
[Serializable]
[System.Runtime.CompilerServices.TypeForwardedFrom("System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public sealed partial class Bitmap : Image
public sealed class Bitmap : Image
{
private static readonly Color s_defaultTransparentColor = Color.LightGray;

Expand Down Expand Up @@ -53,12 +54,37 @@ public Bitmap(Stream stream) : this(stream, false)
{
}

public unsafe Bitmap(Stream stream, bool useIcm)
{
ArgumentNullException.ThrowIfNull(stream);

using DrawingCom.IStreamWrapper streamWrapper = DrawingCom.GetComWrapper(new GPStream(stream));

IntPtr bitmap = IntPtr.Zero;
if (useIcm)
{
Gdip.CheckStatus(Gdip.GdipCreateBitmapFromStreamICM(streamWrapper.Ptr, &bitmap));
}
else
{
Gdip.CheckStatus(Gdip.GdipCreateBitmapFromStream(streamWrapper.Ptr, &bitmap));
}

ValidateImage(bitmap);

SetNativeImage(bitmap);
EnsureSave(this, null, stream);
}

public Bitmap(Type type, string resource) : this(GetResourceStream(type, resource))
{
}

private static Stream GetResourceStream(Type type!!, string resource!!)
private static Stream GetResourceStream(Type type, string resource)
{
ArgumentNullException.ThrowIfNull(type);
ArgumentNullException.ThrowIfNull(resource);

Stream? stream = type.Module.Assembly.GetManifestResourceStream(type, resource);
if (stream == null)
{
Expand All @@ -72,8 +98,10 @@ public Bitmap(int width, int height) : this(width, height, PixelFormat.Format32b
{
}

public Bitmap(int width, int height, Graphics g!!)
public Bitmap(int width, int height, Graphics g)
{
ArgumentNullException.ThrowIfNull(g);

IntPtr bitmap;
int status = Gdip.GdipCreateBitmapFromGraphics(width, height, new HandleRef(g, g.NativeGraphics), out bitmap);
Gdip.CheckStatus(status);
Expand Down Expand Up @@ -107,8 +135,10 @@ public Bitmap(Image original, Size newSize) : this(original, newSize.Width, newS
{
}

public Bitmap(Image original!!, int width, int height) : this(width, height, PixelFormat.Format32bppArgb)
public Bitmap(Image original, int width, int height) : this(width, height, PixelFormat.Format32bppArgb)
{
ArgumentNullException.ThrowIfNull(original);

using (Graphics g = Graphics.FromImage(this))
{
g.Clear(Color.Transparent);
Expand Down

This file was deleted.

This file was deleted.

Loading