Skip to content

Commit 1cf033d

Browse files
authored
Clean up unused locals in System.Drawing.Common (dotnet#32212)
* Clean up unused locals in System.Drawing.Common * Remove BufferedStream, use MemoryStream.ToArray()
1 parent 19d5b8c commit 1cf033d

3 files changed

Lines changed: 19 additions & 21 deletions

File tree

src/libraries/System.Drawing.Common/src/System/Drawing/Pen.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,9 @@ public Color Color
585585

586586
if (value != _color)
587587
{
588+
#if FEATURE_SYSTEM_EVENTS
588589
Color oldColor = _color;
590+
#endif
589591
_color = value;
590592
InternalSetColor(value);
591593

src/libraries/System.Drawing.Common/src/System/Drawing/Printing/PrinterSettings.Windows.cs

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -480,33 +480,27 @@ public bool IsDirectPrintingSupported(Image image)
480480
try
481481
{
482482
image.Save(stream, image.RawFormat);
483-
stream.Position = 0;
484-
using (BufferedStream inStream = new BufferedStream(stream))
485-
{
486-
int pvImageLen = (int)inStream.Length;
487-
byte[] pvImage = new byte[pvImageLen];
488483

489-
int nRead = inStream.Read(pvImage, 0, (int)pvImageLen);
484+
byte[] pvImage = stream.ToArray();
490485

491-
int nEscape = image.RawFormat.Equals(ImageFormat.Jpeg) ? SafeNativeMethods.CHECKJPEGFORMAT : SafeNativeMethods.CHECKPNGFORMAT;
492-
int outData = 0;
486+
int nEscape = image.RawFormat.Equals(ImageFormat.Jpeg) ? SafeNativeMethods.CHECKJPEGFORMAT : SafeNativeMethods.CHECKPNGFORMAT;
487+
int outData = 0;
493488

494-
DeviceContext dc = CreateInformationContext(DefaultPageSettings);
495-
HandleRef hdc = new HandleRef(dc, dc.Hdc);
496-
try
497-
{
498-
bool querySupported = SafeNativeMethods.ExtEscape(hdc, SafeNativeMethods.QUERYESCSUPPORT, sizeof(int), ref nEscape, 0, out outData) > 0;
499-
if (querySupported)
500-
{
501-
isDirectPrintingSupported = (SafeNativeMethods.ExtEscape(hdc, nEscape, pvImageLen, pvImage, sizeof(int), out outData) > 0)
502-
&& (outData == 1);
503-
}
504-
}
505-
finally
489+
DeviceContext dc = CreateInformationContext(DefaultPageSettings);
490+
HandleRef hdc = new HandleRef(dc, dc.Hdc);
491+
try
492+
{
493+
bool querySupported = SafeNativeMethods.ExtEscape(hdc, SafeNativeMethods.QUERYESCSUPPORT, sizeof(int), ref nEscape, 0, out outData) > 0;
494+
if (querySupported)
506495
{
507-
dc.Dispose();
496+
isDirectPrintingSupported = (SafeNativeMethods.ExtEscape(hdc, nEscape, pvImage.Length, pvImage, sizeof(int), out outData) > 0)
497+
&& (outData == 1);
508498
}
509499
}
500+
finally
501+
{
502+
dc.Dispose();
503+
}
510504
}
511505
finally
512506
{

src/libraries/System.Drawing.Common/src/System/Drawing/SolidBrush.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ public Color Color
102102

103103
if (_color != value)
104104
{
105+
#if FEATURE_SYSTEM_EVENTS
105106
Color oldColor = _color;
107+
#endif
106108
InternalSetColor(value);
107109

108110
#if FEATURE_SYSTEM_EVENTS

0 commit comments

Comments
 (0)