111,093
社区成员




Bitmap _NewBitmap = new Bitmap(dataGridView1.Width, dataGridView1.Height);
#region
// 为NewBitmap 赋值
#endregion
pictureBox1.Image = myAlpha(_NewBitmap);
pictureBox1.Image.Save(@"c:\1.png");
private Bitmap myAlpha(Bitmap _Bitmap)
{
Graphics _Graphcis = Graphics.FromImage(_Bitmap);
Point _Left1 = new Point(0, 0);
Point _Left2 = new Point(_Bitmap.Width, 0);
Point _Left3 = new Point(_Bitmap.Width, _Bitmap.Height / 2);
Point _Left4 = new Point(0, _Bitmap.Height / 2);
Point[] _Point = new Point[] { _Left1, _Left2, _Left3, _Left4 };
PathGradientBrush _SetBruhs = new PathGradientBrush(_Point, WrapMode.TileFlipY);
_SetBruhs.CenterPoint = new PointF(0, 0);
_SetBruhs.FocusScales = new PointF(_Bitmap.Width / 2, 0);
_SetBruhs.CenterColor = Color.FromArgb(255, 255, 255, 255);
_SetBruhs.SurroundColors = new Color[] { Color.FromArgb(0, 255, 255, 255) };
_Graphcis.FillRectangle(_SetBruhs, new Rectangle(0, 0, _Bitmap.Width, _Bitmap.Height));
return _Bitmap;
}
float[][] nArray ={ new float[] {1, 0, 0, 0, 0},
new float[] {0, 1, 0, 0, 0},
new float[] {0, 0, 1, 0, 0},
new float[] {0, 0, 0, 120, 0}, // 120为透明度
new float[] {0, 0, 0, 0, 1}};
ColorMatrix matrix = new ColorMatrix(nArray);
ImageAttributes attributes = new ImageAttributes();
attributes.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
Bitmap resultImage = new Bitmap(pictureBox1.Image.Width, pictureBox1.Image.Height);
Graphics g = Graphics.FromImage(resultImage);
g.DrawImage(pictureBox1.Image, new Rectangle(0, 0, pictureBox1.Image.Width, pictureBox1.Image.Height), 0, 0, pictureBox1.Image.Width, pictureBox1.Image.Height, GraphicsUnit.Pixel, attributes);
pictureBox1.Image = resultImage;
public Bitmap SetAplha(Bitmap p_Bitmap)
{
Bitmap _SetBitmap = new Bitmap(p_Bitmap.Width, p_Bitmap.Height);
Graphics _GraphisSetBitmap = Graphics.FromImage(_SetBitmap);
_GraphisSetBitmap.DrawImage(p_Bitmap,new Rectangle(0, 0, p_Bitmap.Width, p_Bitmap.Height));
_GraphisSetBitmap.Dispose();
Bitmap _Bitmap = new Bitmap(_SetBitmap.Width, _SetBitmap.Height);
Graphics _Graphcis = Graphics.FromImage(_Bitmap);
Point _Left1 = new Point(0, 0);
Point _Left2 = new Point(_Bitmap.Width, 0);
Point _Left3 = new Point(_Bitmap.Width, _Bitmap.Height / 2);
Point _Left4 = new Point(0, _Bitmap.Height / 2);
Point[] _Point = new Point[] { _Left1, _Left2, _Left3, _Left4 };
PathGradientBrush _SetBruhs = new PathGradientBrush(_Point, WrapMode.TileFlipY);
_SetBruhs.CenterPoint = new PointF(0, 0);
_SetBruhs.FocusScales = new PointF(_Bitmap.Width / 2, 0);
_SetBruhs.CenterColor = Color.FromArgb(0, 251, 252, 253);
_SetBruhs.SurroundColors = new Color[] { Color.FromArgb(255, 251, 252, 253) };
_Graphcis.FillRectangle(_SetBruhs, new Rectangle(0, 0, _Bitmap.Width, _Bitmap.Height));
_Graphcis.Dispose();
BitmapData _NewData = _Bitmap.LockBits(new Rectangle(0, 0, _Bitmap.Width, _Bitmap.Height), ImageLockMode.ReadOnly, _Bitmap.PixelFormat);
byte[] _NewBytes = new byte[_NewData.Stride * _NewData.Height];
Marshal.Copy(_NewData.Scan0, _NewBytes, 0, _NewBytes.Length);
_Bitmap.UnlockBits(_NewData);
BitmapData _SetData = _SetBitmap.LockBits(new Rectangle(0, 0, _SetBitmap.Width, _SetBitmap.Height), ImageLockMode.ReadWrite, _SetBitmap.PixelFormat);
byte[] _SetBytes = new byte[_SetData.Stride * _SetData.Height];
Marshal.Copy(_SetData.Scan0, _SetBytes, 0, _SetBytes.Length);
int _WriteIndex = 0;
for (int i = 0; i != _SetData.Height; i++)
{
_WriteIndex = i * _SetData.Stride + 3;
for (int z = 0; z != _SetData.Width; z++)
{
_SetBytes[_WriteIndex] = _NewBytes[_WriteIndex];
_WriteIndex += 4;
}
}
Marshal.Copy(_SetBytes, 0, _SetData.Scan0, _SetBytes.Length);
_SetBitmap.UnlockBits(_SetData);
return _SetBitmap;
}