dotnet / dotnet-api-docs

.NET API reference documentation (.NET 5+, .NET Core, .NET Framework)
https://docs.microsoft.com/dotnet/api/
Other
738 stars 1.57k forks source link

Example in Graphics.FromImage(Image) Method Does Not work #10502

Open MaxFun opened 1 month ago

MaxFun commented 1 month ago

Type of issue

Code doesn't work

Description

[Enter feedback here] Code example when pasted into Windows Forms causes an error. The error image

First the information on Graphics.FromImage(Image) Method is so vague anyone who does no already know how to use it gain nothing from the page.

Second the information on Graphics.FromImage(Image) Method is so vague it give no clue where the example code goes in the Windows Forms or how to call it

It seem that any article from microsoft that has a article author of @dotnet-bot has broken code and has cryptic information.

It seem that any example in microsoft's "Learn" documents should to should be detailed enough for someone to "Lean" from

Page URL

https://learn.microsoft.com/en-us/dotnet/api/system.drawing.graphics.fromimage?view=net-8.0&redirectedfrom=MSDN#System_Drawing_Graphics_FromImage_System_Drawing_Image_

Content source URL

https://github.com/dotnet/dotnet-api-docs/blob/main/xml/System.Drawing/Graphics.xml

Document Version Independent Id

5c2e068b-9590-00ef-41c6-a0ad249716c7

Article author

@dotnet-bot

dotnet-policy-service[bot] commented 1 month ago

Tagging subscribers to this area: @dotnet/area-system-drawing

ViktorHofer commented 1 month ago

cc @JeremyKuhne

JeremyKuhne commented 1 month ago

@MaxFun as there is no image path that is guaranteed to be available, we can't really make this work without the user modifying the sample. We can certainly clarify that you need to replace the file name with one that exists.

The "ambiguous" error you're getting is because you have two Image classes in scope in your using statements. You can:

MaxFun commented 1 month ago

Even when I replace "SampImag.jpg" with a real image file "1_2024-01-20_07-27-18_large.jpg" located in the same folder as the Form1.cs I get the error Image

So, what should the example look like to work? Also, there are no using statements in the example code?