24h購物| | PChome| 登入
2010-11-30 09:16:33| 人氣14,112| 回應1 | 上一篇 | 下一篇

[C#]載入影像檔

推薦 0 收藏 0 轉貼0 訂閱站台

C# 提供下列兩種直接載入影像檔的方式

1. Image myImg = Image.FromFile("file path");

2. Bitmap myBmp = Bitmap.FromFile("file path");

   或 Bitmap myBmp = new Bitmap("file path");

  影像寬度: myBmp.Size.Width  

 影像高度:myBmp.Size.Height

 程式中加入下列程式碼:

 using System.Drawing;

this.openFileDialog1.Filter = "所有檔案|*.*|BMP File| *.bmp|JPEG File|*.jpg| GIF File|*.gif";

//選取圖檔類型 

if (openFileDialog1.ShowDialog() == DialogResult.OK)   ////由對話框選取圖檔
    {
      Bitmap myBmp = new Bitmap(openFileDialog1.FileName);
      
PictureBox1.Image = (Image) myBmp;
     }

將影像像素顏色資訊轉為陣列:

            Bitmap myBmp = new Bitmap("file path");
            int Height = myBmp.Height;
            int Width  = myBmp.Width;
            int[,,] rgbData = new int[Width,Height,3];

           for(int y=0;y<Height;y++){
                for(int x=0;x<Width;x++){
                    Color color= myBmp.GetPixel(x,y);
                    rgbData[x, y, 0] = color.R;
                    rgbData[x, y, 1] = color.G;
                    rgbData[x, y, 2] = color.B;
                }
            }

台長: Chris C.S Huang
人氣(14,112) | 回應(1)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: C# |
此分類下一篇:[C#]從ftp server下載檔案
此分類上一篇:[C#] 字串處理

jw4508@gmail.com
請問,修改後的像素陣列如何轉為影像
2016-02-29 09:34:06
是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文