【问题标题】:Transparent Gradient Reflection - VB.NET?透明渐变反射 - VB.NET?
【发布时间】:2013-04-28 03:52:30
【问题描述】:

我想知道如何添加倒置渐变反射,类似于:

我会首先推测将位图倒置。然后,在 Photoshop 中,我会为图像添加一个 alpha 蒙版,从上到下的黑色/白色渐变。

如何在 VB.NET 中添加 alpha 蒙版/渐变组合?我似乎找不到任何功能。

【问题讨论】:

  • 是的,但是如何使用渐变?

标签: vb.net bitmap alpha


【解决方案1】:

这是使用Bitmaps的一种方式

Dim bm_src1 As Bitmap = CType(pb1.Image.Clone, Bitmap)
Dim bm_out As New Bitmap(bm_src1.Width, bm_src1.Height)
Using gr As Graphics = Graphics.FromImage(bm_out)
  'Flip image
  gr.TranslateTransform(CSng(bm_src1.Width / 2), CSng(bm_src1.Height / 2))
  gr.RotateTransform(180)
  gr.TranslateTransform(-CSng(bm_src1.Width / 2), -CSng(bm_src1.Height / 2))
  ' Give the images alpha gradients.
  Dim alpha As Integer
  For x As Integer = 0 To bm_src1.Width - 1
    For y As Integer = 0 To bm_src1.Height - 1
      alpha = (255 * y) \ bm_src1.Height
      Dim clr As Color = bm_src1.GetPixel(x, y)
      clr = Color.FromArgb(alpha, clr.R, clr.G, clr.B)
      bm_src1.SetPixel(x, y, clr)
    Next
  Next
  ' Draw the images onto the result.
  gr.DrawImage(bm_src1, 0, 0)
End Using
' Display the result.
pbResult.Image = bm_out 'picturebox output

【讨论】:

  • 当我在 PictureBox 中查看此图像时,它有黑色背景。有没有办法解决这个问题?另外,我怎样才能让它产生新的反射位图,只有原始高度的 1/3,所以它反映了 src 的底部三分之一?
  • 该问题的后半部分没关系。有什么方法可以提高性能吗?对于大型位图,按像素绘制速度非常慢。
  • 提前制作图片,如果您不需要动态显示它们。
  • 不幸的是,我确实需要它们动态。我该如何解决黑色背景问题?
  • 适用于任何具有 PixelFormat32bppArgb 的源图像。
猜你喜欢
  • 1970-01-01
  • 2011-01-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多