- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
有这样一张图片(原始大小增加了 100%):
在 C# 或 Vb.Net 下,我想知道我是否可以使用颜色矩阵或其他解决方法将亮度/亮度仅增加到该图像的白色/灰色,同时保持黑色背景颜色不变?
换句话说,我想让白色十字更亮(只有十字,白色/灰色像素)。
这是我期望达到的亮度结果:
两张图片均来自第三方应用程序,我显示的第一张图片来自未聚焦的关闭按钮,第二张图片是相同的按钮聚焦,图片的黑色部分是第三个的背景-派对应用
事情是,出于个人原因,在我自己的应用程序中,我将该图像用作关闭按钮和相同的背景颜色,然后我只是想通过为“X”提供亮度来模拟按钮焦点"在该图像中,我需要对其他图像执行相同的操作。
我的图像处理知识很差,我一直在寻找下面这样的方法,但我无法得到预期的结果,因为整个图像的亮度增加了:
Adjust brightness contrast and gamma of an image
我正在尝试使用@Paul Ishak 方法。
我在图片框上设置了图像,想法是当用户悬停控件时增加亮度,并在鼠标离开时重置图像,
我第二次尝试调整亮度时,它在这一行抛出一个 ArgumentException:
bm = New Bitmap(image.Width, image.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
带有此消息:
A first chance exception of type 'System.ArgumentException' occurred in System.Drawing.dll
这是我正在使用的代码,有什么问题吗?:
Private minimizeBitmap As Bitmap
Private Sub PictureBox_MinimizeButton_MouseEnter(ByVal sender As Object, ByVal e As EventArgs) _
Handles PictureBox_MinimizeButton.MouseEnter
Dim pcb As PictureBox = DirectCast(sender, PictureBox)
If Me.minimizeBitmap Is Nothing Then
Me.minimizeBitmap = New Bitmap(pcb.ClientRectangle.Width, pcb.ClientRectangle.Height)
pcb.DrawToBitmap(Me.minimizeBitmap, pcb.ClientRectangle)
End If
pcb.BackgroundImage = BrightenPixels(Me.minimizeBitmap, threshold:=33, modTimes:=5D)
End Sub
Private Sub PictureBox_MinimizeButton_MouseLeave(ByVal sender As Object, ByVal e As EventArgs) _
Handles PictureBox_MinimizeButton.MouseLeave
If Me.minimizeBitmap IsNot Nothing Then
Me.minimizeBitmap.Dispose()
End If
DirectCast(sender, PictureBox).BackgroundImage = Nothing
End Sub
Public Function BrightenPixels(ByVal image As Bitmap, threshold As Decimal, modTimes As Decimal) As Bitmap
Dim bmp As Bitmap
modTimes = Math.Abs(modTimes)
If image Is Nothing Then
Throw New ArgumentNullException(paramname:="image")
End If
Try
bmp = New Bitmap(image.Width, image.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
Catch ex As Exception
MsgBox(ex.GetType.Name)
MsgBox(ex.Message)
End Try
Dim g As Graphics = Graphics.FromImage(bmp)
g.DrawImage(image, New Point(0, 0))
Dim rect As New Rectangle(New Point(0, 0), bmp.Size)
Dim bitmapData As System.Drawing.Imaging.BitmapData = bmp.LockBits(rect, Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
Dim ptr As IntPtr = bitmapData.Scan0
Dim byteCount As Integer = bitmapData.Stride * bitmapData.Height
Dim argb(byteCount - 1) As Byte
Marshal.Copy(ptr, argb, 0, byteCount)
For i As Integer = 0 To byteCount - 1 Step 4
Dim red As Decimal = argb(i + 2)
Dim green As Decimal = argb(i + 1)
Dim blue As Decimal = argb(i)
Dim percentR As Decimal = (red / 255) * 100
Dim percentG As Decimal = (green / 255) * 100
Dim percentB As Decimal = (blue / 255) * 100
Dim aboveThresholdCount As Integer = 0
If percentR > threshold Then aboveThresholdCount += 1
If percentG > threshold Then aboveThresholdCount += 1
If percentB > threshold Then aboveThresholdCount += 1
' Label3.Text = aboveThresholdCount.ToString
If aboveThresholdCount = 3 Then
red = red * modTimes
green = green * modTimes
blue = blue * modTimes
If red > 255 Then red = 255
If green > 255 Then green = 255
If blue > 255 Then blue = 255
End If
argb(i + 2) = CByte(Math.Round(red, 0))
argb(i + 1) = CByte(Math.Round(green, 0))
argb(i) = CByte(Math.Round(blue, 0))
Next
Marshal.Copy(argb, 0, ptr, byteCount)
bmp.UnlockBits(bitmapData)
Return bmp
End Function
最佳答案
此示例将显示在鼠标进入和离开“X”时修改的图像。
(示例 2 会将图像缩小 50%)
请尝试为此示例创建一个新的 Visual Basic Winforms 应用程序。请在修改之前按原样尝试此示例!
1.) 创建新项目
2.) 用这段代码替换 Form1 的所有代码(只修改图像的路径,没有别的)
3.) 点击运行。
4.) 将鼠标移入和移出“X”
示例 1:
Option Strict On
Option Explicit On
Option Infer Off
Public Class Form1
Private originalPic As Bitmap = Nothing
Friend WithEvents PictureBox1 As New PictureBox With {.Parent = Me, .Location = New Point(10, 10)}
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'Only modify this line to the location of your "x" image'
Dim exPath As String = System.IO.Path.Combine(My.Computer.FileSystem.SpecialDirectories.Desktop, "picexample.jpg")
AddHandler PictureBox1.MouseMove, AddressOf PictureBox1_MouseMove
If System.IO.File.Exists(exPath) Then
originalPic = CType(Image.FromFile(exPath), Bitmap)
PictureBox1.Size = originalPic.Size
PictureBox1.Image = originalPic
Else
Application.Exit()
End If
End Sub
Public Function BrightenPixels(ByVal Image As Bitmap, threshold As Decimal, modTimes As Decimal) As Bitmap
modTimes = Math.Abs(modTimes)
If Image Is Nothing Then Return Nothing
Dim bm As New Bitmap(Image.Width, Image.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
Dim g As Graphics = Graphics.FromImage(bm)
g.DrawImage(Image, New Point(0, 0))
Dim rect As New Rectangle(New Point(0, 0), bm.Size)
Dim bitmapData As System.Drawing.Imaging.BitmapData = bm.LockBits(rect, Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
Dim ptr As IntPtr = bitmapData.Scan0
Dim byteCount As Integer = bitmapData.Stride * bitmapData.Height
Dim argb(byteCount - 1) As Byte
System.Runtime.InteropServices.Marshal.Copy(ptr, argb, 0, byteCount)
For i As Integer = 0 To byteCount - 1 Step 4
Dim alpha As Decimal = argb(i + 3)
Dim red As Decimal = argb(i + 2)
Dim green As Decimal = argb(i + 1)
Dim blue As Decimal = argb(i)
Dim percentR As Decimal = (red / 255) * 100
Dim percentG As Decimal = (green / 255) * 100
Dim percentB As Decimal = (blue / 255) * 100
Dim aboveThresholdCount As Integer = 0
If percentR > threshold Then aboveThresholdCount += 1
If percentG > threshold Then aboveThresholdCount += 1
If percentB > threshold Then aboveThresholdCount += 1
If aboveThresholdCount = 3 Then
red = red * modTimes
green = green * modTimes
blue = blue * modTimes
If red > 255 Then red = 255
If green > 255 Then green = 255
If blue > 255 Then blue = 255
End If
argb(i + 2) = CByte(Math.Round(red, 0))
argb(i + 1) = CByte(Math.Round(green, 0))
argb(i) = CByte(Math.Round(blue, 0))
Next
System.Runtime.InteropServices.Marshal.Copy(argb, 0, ptr, byteCount)
bm.UnlockBits(bitmapData)
Return bm
End Function
Private Sub PictureBox1_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseMove
Dim intersectionRect As New Rectangle(13, 18, 22, 21)
Dim mouseRect As New Rectangle(PictureBox1.PointToClient(MousePosition), New Size(1, 1))
Me.Text = mouseRect.ToString
If intersectionRect.IntersectsWith(mouseRect) Then
Dim tmp As Bitmap = BrightenPixels(originalPic, 33, 1.5D)
'---------------------Delete this section of code(inbetween lines) to remove circular highlight----------'
Using g As Graphics = Graphics.FromImage(tmp)
Using gp As New System.Drawing.Drawing2D.GraphicsPath
gp.AddRectangle(intersectionRect)
Using pgp As New System.Drawing.Drawing2D.PathGradientBrush(gp)
Dim center As New PointF(intersectionRect.Left + (intersectionRect.Width \ 2), intersectionRect.Top + (intersectionRect.Height \ 2))
pgp.CenterPoint = center
pgp.CenterColor = Color.FromArgb(64, Color.White)
pgp.SurroundColors = {Color.FromArgb(0, Color.White), Color.FromArgb(0, Color.White)}
g.FillPath(pgp, gp)
End Using
End Using
End Using
'-----------------------------------------------------------------------------------------------------------'
PictureBox1.Image = tmp
Else
PictureBox1.Image = originalPic
End If
End Sub
End Class
示例 2(图像缩小 50%):
Option Strict On
Option Explicit On
Option Infer Off
Public Class Form1
Private originalPic As Bitmap = Nothing
Private intersectionPic As Bitmap = Nothing
Private intersectionRect As New Rectangle(6, 9, 11, 10)
Friend WithEvents PictureBox1 As New PictureBox With {.Parent = Me, .Location = New Point(10, 10)}
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'Only modify this line to the location of your "x" image'
Dim exPath As String = System.IO.Path.Combine(My.Computer.FileSystem.SpecialDirectories.Desktop, "picexample.jpg")
AddHandler PictureBox1.MouseMove, AddressOf PictureBox1_MouseMove
If System.IO.File.Exists(exPath) Then
Dim img As Bitmap = CType(Image.FromFile(exPath), Bitmap)
Dim bm As New Bitmap(img.Width \ 2, img.Height \ 2, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
Dim g1 As Graphics = Graphics.FromImage(bm)
Dim cRect As New Rectangle(New Point(0, 0), bm.Size)
g1.DrawImage(CType(Image.FromFile(exPath), Bitmap), cRect)
originalPic = bm
Dim tmp As Bitmap = BrightenPixels(originalPic, 33, 1.5D)
'---------------------Delete this section of code(inbetween lines) to remove circular highlight----------'
Using g2 As Graphics = Graphics.FromImage(tmp)
Using gp As New System.Drawing.Drawing2D.GraphicsPath
gp.AddRectangle(intersectionRect)
Using pgp As New System.Drawing.Drawing2D.PathGradientBrush(gp)
Dim center As New PointF(intersectionRect.Left + (intersectionRect.Width \ 2), intersectionRect.Top + (intersectionRect.Height \ 2))
pgp.CenterPoint = center
pgp.CenterColor = Color.FromArgb(128, Color.White)
pgp.SurroundColors = {Color.FromArgb(0, Color.White), Color.FromArgb(0, Color.White)}
g2.FillPath(pgp, gp)
End Using
End Using
End Using
'-----------------------------------------------------------------------------------------------------------'
intersectionPic = tmp
PictureBox1.Size = originalPic.Size
PictureBox1.Image = originalPic
Else
Application.Exit()
End If
End Sub
Public Function BrightenPixels(ByVal Image As Bitmap, threshold As Decimal, modTimes As Decimal) As Bitmap
modTimes = Math.Abs(modTimes)
If Image Is Nothing Then Return Nothing
Dim bm As New Bitmap(Image.Width, Image.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
Dim g As Graphics = Graphics.FromImage(bm)
g.DrawImage(Image, New Point(0, 0))
Dim rect As New Rectangle(New Point(0, 0), bm.Size)
Dim bitmapData As System.Drawing.Imaging.BitmapData = bm.LockBits(rect, Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
Dim ptr As IntPtr = bitmapData.Scan0
Dim byteCount As Integer = bitmapData.Stride * bitmapData.Height
Dim argb(byteCount - 1) As Byte
System.Runtime.InteropServices.Marshal.Copy(ptr, argb, 0, byteCount)
For i As Integer = 0 To byteCount - 1 Step 4
Dim alpha As Decimal = argb(i + 3)
Dim red As Decimal = argb(i + 2)
Dim green As Decimal = argb(i + 1)
Dim blue As Decimal = argb(i)
Dim percentR As Decimal = (red / 255) * 100
Dim percentG As Decimal = (green / 255) * 100
Dim percentB As Decimal = (blue / 255) * 100
Dim aboveThresholdCount As Integer = 0
If percentR > threshold Then aboveThresholdCount += 1
If percentG > threshold Then aboveThresholdCount += 1
If percentB > threshold Then aboveThresholdCount += 1
If aboveThresholdCount = 3 Then
red = red * modTimes
green = green * modTimes
blue = blue * modTimes
If red > 255 Then red = 255
If green > 255 Then green = 255
If blue > 255 Then blue = 255
End If
argb(i + 2) = CByte(Math.Round(red, 0))
argb(i + 1) = CByte(Math.Round(green, 0))
argb(i) = CByte(Math.Round(blue, 0))
Next
System.Runtime.InteropServices.Marshal.Copy(argb, 0, ptr, byteCount)
bm.UnlockBits(bitmapData)
Return bm
End Function
Private Sub PictureBox1_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseMove
Dim mouseRect As New Rectangle(PictureBox1.PointToClient(MousePosition), New Size(1, 1))
Me.Text = mouseRect.ToString
If intersectionRect.IntersectsWith(mouseRect) Then
PictureBox1.Image = intersectionPic
Else
PictureBox1.Image = originalPic
End If
End Sub
End Class
关于.net - 增加图像中特定颜色的亮度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29998095/
我正在尝试学习 Knockout 并尝试创建一个照片 uploader 。我已成功将一些图像存储在数组中。现在我想回帖。在我的 knockout 码(Javascript)中,我这样做: 我在 Jav
我正在使用 php 编写脚本。我的典型问题是如何在 mysql 中添加一个有很多替代文本和图像的问题。想象一下有机化学中具有苯结构的描述。 最有效的方法是什么?据我所知,如果我有一个图像,我可以在数据
我在两个图像之间有一个按钮,我想将按钮居中到图像高度。有人可以帮帮我吗? Entrar
下面的代码示例可以在这里查看 - http://dev.touch-akl.com/celebtrations/ 我一直在尝试做的是在 Canvas 上绘制 2 个图像(发光,然后耀斑。这些图像的链接
请检查此https://jsfiddle.net/rhbwpn19/4/ 图像预览对于第一篇帖子工作正常,但对于其他帖子则不然。 我应该在这里改变什么? function readURL(input)
我对 Canvas 有疑问。我可以用单个图像绘制 Canvas ,但我不能用单独的图像绘制每个 Canvas 。- 如果数据只有一个图像,它工作正常,但数据有多个图像,它不工作你能帮帮我吗? va
我的问题很简单。如何获取 UIImage 的扩展类型?我只能将图像作为 UIImage 而不是它的名称。图像可以是静态的,也可以从手机图库甚至文件路径中获取。如果有人可以为此提供一点帮助,将不胜感激。
我有一个包含 67 个独立路径的 SVG 图像。 是否有任何库/教程可以为每个路径创建单独的光栅图像(例如 PNG),并可能根据路径 ID 命名它们? 最佳答案 谢谢大家。我最终使用了两个答案的组合。
我想将鼠标悬停在一张图片(音乐专辑)上,然后播放一张唱片,所以我希望它向右移动并旋转一点,当它悬停时我希望它恢复正常动画片。它已经可以向右移动,但我无法让它随之旋转。我喜欢让它尽可能简单,因为我不是编
Retina iOS 设备不显示@2X 图像,它显示 1X 图像。 我正在使用 Xcode 4.2.1 Build 4D502,该应用程序的目标是 iOS 5。 我创建了一个测试应用(主/细节)并添加
我正在尝试从头开始以 Angular 实现图像 slider ,并尝试复制 w3school基于图像 slider 。 下面我尝试用 Angular 实现,谁能指导我如何使用 Angular 实现?
我正在尝试获取图像的图像数据,其中 w= 图像宽度,h = 图像高度 for (int i = x; i imageData[pos]>0) //Taking data (here is the pr
我的网页最初通过在 javascript 中动态创建图像填充了大约 1000 个缩略图。由于权限问题,我迁移到 suPHP。现在不用标准 标签本身 我正在通过这个 php 脚本进行检索 $file
我正在尝试将 python opencv 图像转换为 QPixmap。 我按照指示显示Page Link我的代码附在下面 img = cv2.imread('test.png')[:,:,::1]/2
我试图在这个 Repository 中找出语义分割数据集的 NYU-v2 . 我很难理解图像标签是如何存储的。 例如,给定以下图像: 对应的标签图片为: 现在,如果我在 OpenCV 中打开标签图像,
import java.util.Random; class svg{ public static void main(String[] args){ String f="\"
我有一张 8x8 的图片。 (位图 - 可以更改) 我想做的是能够绘制一个形状,给定一个 Path 和 Paint 对象到我的 SurfaceView 上。 目前我所能做的就是用纯色填充形状。我怎样才
要在页面上显示图像,你需要使用源属性(src)。src 指 source 。源属性的值是图像的 URL 地址。 定义图像的语法是: 在浏览器无法载入图像时,替换文本属性告诉读者她们失去的信息。此
**MMEditing是基于PyTorch的图像&视频编辑开源工具箱,支持图像和视频超分辨率(super-resolution)、图像修复(inpainting)、图像抠图(matting)、
我正在尝试通过资源文件将图像插入到我的程序中,如下所示: green.png other files 当我尝试使用 QImage 或 QPixm
我是一名优秀的程序员,十分优秀!