簡單的圖片存取
通過bitmap的getpixel方法擷取每個像素的rgb值 然後把它存入一個檔案,然後再通過讀取這個檔案還原一個bitmap的例子,
。Net就是這麼強大就是這麼bt 也許你你不知道jpg的內部檔案格式 也許你不知道bmp檔案的內部格式(實際上也不是很複雜研究一下就OK啦 ˇ△ˇ)
但是你卻可以藉助.Net內建的GDI 圖形庫這個強大的東東作為橋樑在短時間來完成你想要的功能 ,你看哇哈哈 是不是發現你也會用C#編寫圖片處理工具了 (¯▽¯;) 編程就是這麼的有趣。
啥加浮水印啊 啥調節某個地區的亮度啊 啥。。。。那些都自己整 只要有想法都可以實現
C#代碼
static void Main(string[] args) { //找一個640x480的圖片 讀取檔案並把所有像素轉存到檔案a BinaryWriter sw; if (File.Exists("a")) File.Delete("a"); sw = new BinaryWriter(File.Create("a")); Bitmap img = new Bitmap("a.bmp"); for (int i = 0; i < img.Height; i++) { for (int j = 0; j < img.Width; j++) { Color cor = img.GetPixel(j, i); sw.Write(cor.R); sw.Write(cor.G); sw.Write(cor.B); } } sw.Close(); //從轉存的檔案中讀取位元影像資料 並產生b.jpg BinaryReader br; br = new BinaryReader(new FileStream("a", FileMode.Open)); byte data; Bitmap img2 = new Bitmap(640, 480); for (int i = 0; i < img2.Height; i++) { for (int j = 0; j < img2.Width; j++) { byte r = br.ReadByte(); byte g = br.ReadByte(); byte b = br.ReadByte(); Color cor = Color.FromArgb(r, 0, b); img2.SetPixel(j, i, cor); } } br.Close(); img2.Save("b.jpg", ImageFormat.Jpeg); }