Manthan
Manthan

Reputation: 3914

`Graphics' is an ambiguous reference between `UnityEngine.Graphics' and `System.Drawing.Graphics'

I am having a unity project in which I have made a c# scripting to change the brightness of an image.

As using System.Drawing is not supported in unity, I imported a System.Drawing.dll file for that.

So I was able to use that.

Here is my code below.

using UnityEngine;
using System.Collections;
using System;
using System.Drawing;
using System.Drawing.Imaging;


public class NewBehaviourScript : MonoBehaviour {

    // Use this for initialization
    void Start () {

    }

    // Update is called once per frame
    void Update () 
    {
        Bitmap originalImage;
        Bitmap adjustedImage;
        float brightness = 1.0f; // no change in brightness
        float contrast = 2.0f; // twice the contrast
        float gamma = 1.0f; // no change in gamma

        float adjustedBrightness = brightness - 1.0f;
        // create matrix that will brighten and contrast the image
        float[][] ptsArray ={
            new float[] {contrast, 0, 0, 0, 0} , // scale red
            new float[] {0, contrast, 0, 0, 0} , // scale green
            new float[] {0, 0, contrast, 0, 0} , // scale blue
            new float[] {0, 0, 0, 1.0f, 0} , // don't scale alpha
            new float[] {adjustedBrightness, adjustedBrightness, adjustedBrightness, 0, 1}} ;

        ImageAttributes imageAttributes = new ImageAttributes();
        imageAttributes.ClearColorMatrix();
        imageAttributes.SetColorMatrix(new ColorMatrix(ptsArray), ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
        imageAttributes.SetGamma(gamma, ColorAdjustType.Bitmap);


        Graphics g = Graphics.FromImage(adjustedImage);
        g.DrawImage(originalImage, new Rectangle(0,0,adjustedImage.Width,adjustedImage.Height)
                    ,0,0,originalImage.Width,originalImage.Height,
                    GraphicsUnit.Pixel, imageAttributes);
    }
}

With the error above, I tried it to solve using this but it still doesn't solve my problem.

How could I solve this problem?

Upvotes: 0

Views: 760

Answers (1)

Aniket Inge
Aniket Inge

Reputation: 25725

Why don't you use a fully qualified name instead (which includes the namespace) such as

System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(...

Upvotes: 3

Related Questions