2015-05-05 13 views
0

我有一個統一項目,我已經做了一個c#腳本來改變圖像的亮度。`圖形'是'UnityEngine.Graphics'和'System.Drawing.Graphics'之間的一個模棱兩可的參考

由於使用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,但它仍然不能解決我的問題。

我該如何解決這個問題?

+0

您可以從您的usings刪除'System.Drawing'或使用專門'UnityEngine.Graphics ' –

+0

如果我不使用System.Drawing,它不會讓我使用位圖和所有其他參考框架... – Manthan

回答

3

你爲什麼不使用完全合格的名稱,而不是(其中包括namespace)如

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

+0

感謝您的回覆,但它不會顯示我FromImage。你可以請更新我的代碼?因爲沒有使用System.Drawing,它給了我錯誤的位圖...我該怎麼辦? – Manthan

+0

@Manthan你可以用上面的代碼來試試嗎? –

+0

我已經在我的代碼中試過這個,但是顯示錯誤。 – Manthan