【发布时间】: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 和所有其他,因为它们被引用到该框架......