向zgke请教关于alpha的问题。

tank_2009 2009-09-08 09:25:51


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



我把加入alpha的图像放入到pictureBox中,也没有出现透明。没分了,实在抱歉
...全文
194 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
zgke 2009-09-08
  • 打赏
  • 举报
回复
恩 这个问题..鼠标事件里 你的先判断需要截图不需要..不需要截图就不执行图形操作..看看
tank_2009 2009-09-08
  • 打赏
  • 举报
回复
好吧...非常感谢 ....

另外 我现在让pictureBox随便着鼠标在DataGridView上面移动。感觉pictureBox显示速度非常慢。
鼠标移动速度稍快,pictureBox就显示不出,请问可以有别的方法来代替,一个图像跟随着鼠标移动,并且效率更高吗?

imageList因为size有限,所以没有考虑。
zgke 2009-09-08
  • 打赏
  • 举报
回复
简单的办法你可以考虑使用 多传递一个参数来实现..
tank_2009 2009-09-08
  • 打赏
  • 举报
回复

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;




我另外找了一个代码,实现将picturebox中图像变为半透明状,但是能再帮我改一下,和你的那个方法结合,形成渐变为透明的效果。能实现吗?
zgke 2009-09-08
  • 打赏
  • 举报
回复
自己写个更改ALPAH的方法 不知道可以不
tank_2009 2009-09-08
  • 打赏
  • 举报
回复
up............
tank_2009 2009-09-08
  • 打赏
  • 举报
回复
我把这句代码加在 FillRectangle 的后面了

但是还是白色的。
zgke 2009-09-08
  • 打赏
  • 举报
回复
_Graphcis.CompositingMode = CompositingMode.SourceOver;

这样.
tank_2009 2009-09-08
  • 打赏
  • 举报
回复
第2个方法 附值的时候就设置透明

应该怎样做呢?
zgke 2009-09-08
  • 打赏
  • 举报
回复
第1个方法 myAlpha传递背景色.
第2个方法 附值的时候就设置透明
tank_2009 2009-09-08
  • 打赏
  • 举报
回复
赋值确实不是透明的。
tank_2009 2009-09-08
  • 打赏
  • 举报
回复
没有透明吧...PictureBox的背景是透明的。但是赋值后,图像上下应该是橙色。
zgke 2009-09-08
  • 打赏
  • 举报
回复
赋值的时候就已经不是透明的了把
tank_2009 2009-09-08
  • 打赏
  • 举报
回复
tank_2009 2009-09-08
  • 打赏
  • 举报
回复
结贴先...感谢zgke.
zgke 2009-09-08
  • 打赏
  • 举报
回复
这样 最笨的办法

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;

}

内容概要:本文针对无刷直流电机驱动的电子机械制动(EMB)执行器,建立了考虑Stribeck摩擦特性的非线性耦合动力学模型,并在Simulink环境中完成了系统级仿真分析。研究综合集成了电机动力学、齿轮传动机构与制动执行机构的动力学特性,构建了高保真的机电一体化系统模型。重点引入Stribeck摩擦模型以精确描述低速工况下执行器内部存在的静摩擦、粘滞摩擦与库仑摩擦之间的过渡行为,有效提升了系统在启停、反向运动等瞬态过程中的动态响应仿真精度。通过多工况仿真验证了模型的有效性,能够准确反映摩擦引起的爬行、滞后与定位误差等非线性现象,为EMB系统的高性能控制算法设计(如摩擦补偿、滑模控制)与结构优化提供了高可信度的仿真平台。; 适合人群:从事汽车电子制动系统、电机驱动控制、机电系统建模与仿真研究的研究生、科研人员及工程技术人员,需具备扎实的机械动力学、自动控制理论基础和MATLAB/Simulink仿真能力。; 使用场景及目标:①用于高精度电子机械制动系统的设计验证与性能预测;②为消除摩擦非线性影响的先进控制策略(如自适应控制、智能控制)提供精确的被控对象模型;③深入探究Stribeck摩擦等非线性因素对系统动态性能(如响应延迟、稳态误差)的作用机理; 阅读建议:读者应结合提供的Simulink模型文件,深入剖析Stribeck摩擦模块的数学实现与参数辨识方法,建议通过改变输入指令(如阶跃、正弦)和负载条件进行对比仿真,以直观理解非线性摩擦对系统动态特性的影响。

111,129

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧