[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;
}
}
上一篇:[C#] 字串處理
請問,修改後的像素陣列如何轉為影像