我有一個統一項目,我已經做了一個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,但它仍然不能解決我的問題。
我該如何解決這個問題?
您可以從您的usings刪除'System.Drawing'或使用專門'UnityEngine.Graphics ' –
如果我不使用System.Drawing,它不會讓我使用位圖和所有其他參考框架... – Manthan