CosmosOS / Cosmos

Cosmos is an operating system "construction kit". Build your own OS using managed languages such as C#, VB.NET, and more!
https://www.goCosmos.org
BSD 3-Clause "New" or "Revised" License
2.93k stars 554 forks source link

[CGS] Add a method to draw an image #606

Closed fanoI closed 6 years ago

fanoI commented 7 years ago

Taking again inspiration from System.Drawing.Graphics the method should be this: public void DrawImage(Image image, int x, int y)

Image is an abstract class from which BitMap and MetaFile (?) inherit the primary objective of this issue would to load a simple 32 bit bitmap file from disk and show it on screen so if plugs are needed try to limit to this.

System.Drawing.Graphics has another overload of this method: public void DrawImage(Image image, int x, int y, int width, int height)

this is not be needed in CGS probably resizing could be done better at higher level (in the Widget ToolKit or in a user application).

fanoI commented 7 years ago

601

OffensiveCheese commented 7 years ago

check out cjhannah's image class

fanoI commented 7 years ago

Probably DrawImage is a thing that should be done at a higher level or in intermediate "library" or directly on the tool kit itself, I'm unsure if it would really part of CGS. If @cjhannah wants to help to port his image class to CGS will be wonderful.

fanoI commented 7 years ago

Why the variable 'color'? An image can be seen as an array of colored pixels so it is not needed... or are you thinking of a border color? This should be done at higher level (in the widget toolkit) in the "PictureBox" object.

The method prototype was only an example in any case.

bluethefoxyt commented 7 years ago

@fanoI there is no fill for the rectangles that i can see just a border

bluethefoxyt commented 7 years ago

also no way to find the edge of the canvas to fit to the edge of the screen

fanoI commented 7 years ago

DrawFilledRectangle() is one of the methods that should be implemented as you can see here: https://github.com/CosmosOS/Cosmos/issues/603

if you want you could start from here.

Geramy commented 7 years ago

I would say just implement the functions as the System.Drawing.Graphics class is so you have portability and if you want to add border then create a library for people.

fanoI commented 7 years ago

Yes I think having a sort of compatibility / familiarity with the .Net System.Drawing is good! Indeed my idea is to use the same prototype of the .Net class.

jp2masa commented 7 years ago

I think that System.Drawing in .NET Core only has primitive types (Color, Point,...).

fanoI commented 7 years ago

They are in the process of porting the Mono version of System.Drawing (so to have something working on "Unix" too) and I think they will port DrawImage too: https://github.com/dotnet/corefx/issues/20712

To be clear for me DrawImage() means a simple bitmap not a GIF / JPEG / PNG the image conversion to BMP shall be done by an high level library.

If not what is your idea? In the end draw a bitmap is not simply a for() of DrawPoint() or I make it too simple?

jp2masa commented 7 years ago

We can plug System.Drawing as a graphics library, then it would call the draw methods to draw images and text. I think that there's no need to have a DrawImage method in Canvas, as no graphics driver will have a specific implementation for it.

fanoI commented 7 years ago

The motive because I have not plugged directly System.Graphics was because to for example do a DrawRectangle() you needed a Winform but now in CoreFx they have said that instead System.Drawing is the building block of Winform... I'm a little confused now.

jp2masa commented 7 years ago

Graphics aren't a priority for now, so let's keep things simple. When we move to .NET Core 2.0, we can decide better what to do.

fanoI commented 7 years ago

I concord better to wait Net Core 2.0 / Net Standard and see what they decide to do with System.Drawing obviously we can / should participate in the process so that it could be usable by us too.