c# - How does System.Drawing.Image class work? -


i wondering why possible set image property of picturebox, when image class abstract class, , therefore cannot instantiated.

does image.fromfile() method create bitmap (a derived class image) uses display in picturebox? if when creating image file not .bmp ,if example use:

image.fromfile("test.png") 

does convert .png file bitmap in memory before displaying it?

i know how of above, , know works, trying head around how works when image abstract not able find information on matter - explanations appreciated!

the fact image.fromfile("test.png") returns image not mean returns instance of image class. because image abstract can return subclass of image.

the method fromfile determines returns based on finds in file calling gdipgetimagetype.

also: class bitmap not reserved .bmp files. using decoder fromfile method turns bytes of file in memory representation of image. in general big blob of bytes specify red, blue, green , alpha values of pixels. stored in instance of bitmap class.

an other type of file metafile. these files not contain pixel information vector information. when metafile read not turned pixel data in memory vector information stored. enables metafile resize image without loss of quality.

the method called fromfile looks this:

internal static image createimageobject(intptr nativeimage) {   int type = -1;   int imagetype = safenativemethods.gdip.gdipgetimagetype(new handleref((object) null, nativeimage), out type);   if (imagetype != 0)     throw safenativemethods.gdip.statusexception(imagetype);   switch (type)   {     case 1:       return (image) bitmap.fromgdiplus(nativeimage);     case 2:       return (image) metafile.fromgdiplus(nativeimage);     default:       throw new argumentexception(system.drawing.sr.getstring("invalidimage"));   } } 

based on image type either metafile or bitmap obect created , loaded. these 2 type derive image.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -