C#影像處理

來源:互聯網
上載者:User

簡單的圖片存取

通過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);        }
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.