2010-11-30 09:16:33Chris C.S Huang

[C#]載入影像檔

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;
                }
            }

jw4508@gmail.com 2016-02-29 09:34:06

請問,修改後的像素陣列如何轉為影像