using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;namespace BMP文件的打开
{
class Program
{
static void Main(string[] args)
{
for(int 图片宽度=1;图片宽度<4;图片宽度++)
for (int 图片高度 = 1; 图片高度 < 3; 图片高度++)
{
string 指定像素颜色字符串 = 颜色转为字符串(图片宽度,图片高度);
Console.WriteLine("{0}", 指定像素颜色字符串);
}
}
static string 颜色转为字符串(int 图片宽度,int 图片高度)
{
Bitmap bmp = new Bitmap(@"C:\4.BMP");
Color pixelColor = bmp.GetPixel(图片宽度,图片高度);
string 红色哟 = 红色(pixelColor);
string 绿色哟 = 绿色(pixelColor);
string 蓝色哟 = 蓝色(pixelColor);
//Console.WriteLine("{0}", 红色哟);
//Console.WriteLine("{0}", 绿色哟);
//Console.WriteLine("{0}", 蓝色哟);
int 红色字符串长度 = 红色哟.Length;
int 绿色字符串长度 = 绿色哟.Length;
int 蓝色字符串长度 = 蓝色哟.Length;
//Console.WriteLine("{0}", 红色字符串长度);
//Console.WriteLine("{0}", 绿色字符串长度);
//Console.WriteLine("{0}", 蓝色字符串长度);
if(红色字符串长度 < 8)
{
for (int i = 1; i < 9 - 红色字符串长度;i++ )
{
红色哟 = 红色哟 + "0";
}
}
if (绿色字符串长度 < 8)
{
for (int i = 1; i < 9 - 绿色字符串长度; i++)
{
绿色哟 = 绿色哟 + "0";
}
}
if (蓝色字符串长度 < 8)
{
for (int i = 1; i < 9 - 蓝色字符串长度; i++)
{
蓝色哟 = 蓝色哟 + "0";
}
}
//Console.WriteLine("{0}", 红色哟);
//Console.WriteLine("{0}", 绿色哟);
//Console.WriteLine("{0}", 蓝色哟);
string 像素字符串 = 红色哟 + 绿色哟 + 蓝色哟;
return 像素字符串;
}
public static string 红色(Color color)
{
string r = Convert.ToString(long.Parse(color.R.ToString()), 2); if (r.Length == 1)
r = 0 + r; return r;
} public static string 绿色(Color color)
{
string g = Convert.ToString(long.Parse(color.G.ToString()), 2); if (g.Length == 1)
g = 0 + g;
return g;
} public static string 蓝色(Color color)
{
string b = Convert.ToString(long.Parse(color.B.ToString()), 2); if (b.Length == 1)
b = 0 + b; return b;
} }
}
这段程序单独运行完全正常,弄到另一个程序当函数用时,VS2008非说"命名空间“System”中不存在类型或命名空间名称“Drawing”(是缺少程序集引用吗?)"要郁闷死了
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;namespace BMP文件的打开
{
class Program
{
static void Main(string[] args)
{
for(int 图片宽度=1;图片宽度<4;图片宽度++)
for (int 图片高度 = 1; 图片高度 < 3; 图片高度++)
{
string 指定像素颜色字符串 = 颜色转为字符串(图片宽度,图片高度);
Console.WriteLine("{0}", 指定像素颜色字符串);
}
}
static string 颜色转为字符串(int 图片宽度,int 图片高度)
{
Bitmap bmp = new Bitmap(@"C:\4.BMP");
Color pixelColor = bmp.GetPixel(图片宽度,图片高度);
string 红色哟 = 红色(pixelColor);
string 绿色哟 = 绿色(pixelColor);
string 蓝色哟 = 蓝色(pixelColor);
//Console.WriteLine("{0}", 红色哟);
//Console.WriteLine("{0}", 绿色哟);
//Console.WriteLine("{0}", 蓝色哟);
int 红色字符串长度 = 红色哟.Length;
int 绿色字符串长度 = 绿色哟.Length;
int 蓝色字符串长度 = 蓝色哟.Length;
//Console.WriteLine("{0}", 红色字符串长度);
//Console.WriteLine("{0}", 绿色字符串长度);
//Console.WriteLine("{0}", 蓝色字符串长度);
if(红色字符串长度 < 8)
{
for (int i = 1; i < 9 - 红色字符串长度;i++ )
{
红色哟 = 红色哟 + "0";
}
}
if (绿色字符串长度 < 8)
{
for (int i = 1; i < 9 - 绿色字符串长度; i++)
{
绿色哟 = 绿色哟 + "0";
}
}
if (蓝色字符串长度 < 8)
{
for (int i = 1; i < 9 - 蓝色字符串长度; i++)
{
蓝色哟 = 蓝色哟 + "0";
}
}
//Console.WriteLine("{0}", 红色哟);
//Console.WriteLine("{0}", 绿色哟);
//Console.WriteLine("{0}", 蓝色哟);
string 像素字符串 = 红色哟 + 绿色哟 + 蓝色哟;
return 像素字符串;
}
public static string 红色(Color color)
{
string r = Convert.ToString(long.Parse(color.R.ToString()), 2); if (r.Length == 1)
r = 0 + r; return r;
} public static string 绿色(Color color)
{
string g = Convert.ToString(long.Parse(color.G.ToString()), 2); if (g.Length == 1)
g = 0 + g;
return g;
} public static string 蓝色(Color color)
{
string b = Convert.ToString(long.Parse(color.B.ToString()), 2); if (b.Length == 1)
b = 0 + b; return b;
} }
}
这段程序单独运行完全正常,弄到另一个程序当函数用时,VS2008非说"命名空间“System”中不存在类型或命名空间名称“Drawing”(是缺少程序集引用吗?)"要郁闷死了
估计是2008里Drawing不在“System”中
2008里面有 System.Drawing的,楼主重建个2008的项目看看点的出来吗?这问题光描述可能很难弄哦