我正在尝试获取位图的alpha分量。使用GetPixel
方法只获取rgb,alpha组件全部为255(不透明)。这是我尝试过的:
System.Drawing.Color tmp;
int rows = bitmap.Width;
int cols = bitmap.Height;
string[,] alphaMatrix = new string[rows,cols];
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{
tmp = bitmap.GetPixel(i, j);
alphaMatrix[i, j] = tmp.ToArgb().ToString();
}
}
return alphaMatrix;
编辑:
最初我的图片是BitmapImage
,我将其转换为System.Drawing.Bitmap
。我正在使用这种方法:
private System.Drawing.Bitmap BitmapImageToBitmap(BitmapImage bitmapImage)
{
using (MemoryStream outStream = new MemoryStream())
{
BitmapEncoder enc = new BmpBitmapEncoder();
enc.Frames.Add(BitmapFrame.Create(bitmapImage));
enc.Save(outStream);
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(outStream);
return new System.Drawing.Bitmap(bitmap);
}
}