System.Drawing Image Class unavailability

Asked

Viewed 76 times

0

This class is not available.

System.Drawing.Image;

I use Vs 2013 and Netframework 4.5.2 and the dll system.Drawing v.4.0

I already added the references and already imported a "new" dll and is not available.

Just declaring System.Drawing already works.

  • What type of project? What are you trying to do with the code shown above? Declare a variable or make an import (using)?

  • @jbueno using was trying.

1 answer

1

If you want to use this class (Image) in namespace, will have to define a Alias for her.

After that, you can do the following:

using System;
using System.Drawing;
using System.Windows.Forms;
using meuAlias = System.Drawing.Image;

namespace Imagem {
    public partial class TesteImagem : Form {
        public TesteImagem() {
            //Construtor
        }

        public void MeuMetodo() {
            //Acessando diretamente a classe com o caminho completo
            var imagem1 = System.Drawing.Image.FromFile("c:\teste.bmp");

            //Usando o Alias criado no Namespace
            var imagem2 = meuAlias.FromFile("c:\teste.jpg");
        }
    }
}

Remembering that the namespace serve to simplify coding, do not need them if always use full names.
See, we can directly access this method Range, who’s in class Enumerable, which in turn is in the namespace Linq:

var teste = System.Linq.Enumerable.Range(0, 10);

Recommended readings
In C# it is possible to use a local alias for class or namespace?

How to use global namespace alias

Browser other questions tagged

You are not signed in. Login or sign up in order to post.