【问题标题】:`Graphics' is an ambiguous reference between `UnityEngine.Graphics' and `System.Drawing.Graphics'`Graphics' 是 `UnityEngine.Graphics' 和 `System.Drawing.Graphics' 之间的模糊引用
【发布时间】:2015-05-05 06:08:11
【问题描述】:

我有一个统一项目,我在其中编写了一个 c# 脚本来更改图像的亮度。

由于统一不支持使用System.Drawing,因此我为此导入了System.Drawing.dll 文件。

所以我可以使用它。

下面是我的代码。

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);
    }
}

由于上述错误,我尝试解决using this,但仍然没有解决我的问题。

我该如何解决这个问题?

【问题讨论】:

  • 您可以从您的使用中删除System.Drawing 或专门使用UnityEngine.Graphics
  • 如果我不使用 System.Drawing,它不会让我使用 Bitmap 和所有其他,因为它们被引用到该框架......

标签: c# graphics unity3d


【解决方案1】:

为什么不使用完全限定名称(包括namespace),例如

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

【讨论】:

  • 感谢您的回复,但它没有显示 FromImage。你能更新我的代码吗?因为不使用 System.Drawing,它会给我 Bitmap 上的错误...我该怎么办?
  • 当我输入 Graphics g = Graphics.FromImage 时,它​​不会显示 fromImage。如果你有团结,你可以运行上面的代码并检查吗?
  • @Manthan Graphics.FromImageSystem.DrawingGraphics 类中。
  • 是的,我知道,这就是为什么我在我的代码中使用了上面的命名空间,但它仍然不允许我从图像中获取它。显示错误。
  • 发布错误截图和源代码相关部分
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-05-12
  • 2022-06-28
相关资源
最近更新 更多