vb.net照片黑白 vb设置图片框背景颜色
如何用vb编程将彩色图像转换为黑白
我昨天刚用过,效果很好,速度也快
成都创新互联公司-专业网站定制、快速模板网站建设、高性价比定安网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式定安网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖定安地区。费用合理售后完善,十载实体公司更值得信赖。
(代码在下面地址的7楼)
一个用API来完成的例子, 速度比GetPixel快n倍
Option Explicit
'图像处理的一个例子
'Powered by Jadeluo , 2004/02/21
'EMail: Jadeluo@sina.com
Private Type BITMAP
bmType As Long
bmWidth As Long
bmHeight As Long
bmWidthBytes As Long
bmPlanes As Integer
bmBitsPixel As Integer
bmBits As Long
End Type
Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
Private Declare Function GetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long
Private Declare Function SetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long
Private Sub Form_Load()
picShow.BorderStyle = vbBSNone
picShow.Move 0, 0
End Sub
Private Sub cmdLoad_Click()
On Error Resume Next
With CommonDialog1
.Filter = "Picture(*.BMP;*.JPG;*.GIF;*.ICO)|*.BMP;*.JPG;*.GIF;*.ICO|All Files(*.*)|*.*"
.CancelError = True
.ShowOpen
If Err.Number = 0 Then
picShow.AutoSize = True
picShow.Picture = LoadPicture(.FileName)
End If
End With
On Error GoTo 0
End Sub
Private Sub cmdGray_Click()
Dim PicBits() As Byte, PicInfo As BITMAP, BytesPerPixel As Long
Dim R As Byte, G As Byte, B As Byte, Gray As Byte, i As Long
With picShow
.AutoRedraw = True
GetObject .Image, Len(PicInfo), PicInfo
BytesPerPixel = PicInfo.bmBitsPixel \ 8
ReDim PicBits(1 To PicInfo.bmWidth * PicInfo.bmHeight * BytesPerPixel)
GetBitmapBits .Image, UBound(PicBits), PicBits(1)
For i = 0 To UBound(PicBits) \ BytesPerPixel - 1
B = PicBits(i * BytesPerPixel + 1)
G = PicBits(i * BytesPerPixel + 2)
R = PicBits(i * BytesPerPixel + 3)
Gray = R * 0.39 + G * 0.5 + B * 0.11
'下面这一句是将灰度值换算成二值
' If Gray 127 Then Gray = 255 Else Gray = 0
PicBits(i * BytesPerPixel + 1) = Gray
PicBits(i * BytesPerPixel + 2) = Gray
PicBits(i * BytesPerPixel + 3) = Gray
Next i
SetBitmapBits .Image, UBound(PicBits), PicBits(1)
.Refresh
End With
End Sub
vb.net怎么使图像灰度化再输出
在web上可以使用HTML5的特效实现。
在windows forms里面可以直接修改设置图片的属性。
Try
' 图片位置初始化一个image1
Dim image1 As New Bitmap(
"C:\Documents and Settings\All Users\Documents\My Music\music.bmp",
True)
Dim x, y As Integer
' Loop through the images pixels to reset color.
For x = 0 To image1.Width - 1
For y = 0 To image1.Height - 1
Dim pixelColor As Color = image1.GetPixel(x, y)
Dim newColor As Color =
Color.FromArgb(pixelColor.R, 0, 0)
image1.SetPixel(x, y, newColor)
Next
Next
' Set the PictureBox to display the image.
PictureBox1.Image = image1
' Display the pixel format in Label1.
Label1.Text = "Pixel format: " + image1.PixelFormat.ToString()
Catch ex As ArgumentException
MessageBox.Show("There was an error." _
"Check the path to the image file.")
End Try
vb.net 打印问题
可以将打印机默认打印设置改为黑白打印,如果打印对象是RGB配色,打印机驱动转换为CMYK颜色时,黑色都是由彩色墨水组成的
2.可以试一下图片从一个标准灰度图片格式化而来,这样图片自身只有黑白色,也许可以
VB.net 旋转图像时,如何指定填充色
绘制线条采用Draw开头的方法,颜色参数用Pen类;
绘制有填充色的封闭图形采用Fill开头的方法,颜色参数用Brush类;
例如:
'绘制一个实心圆,该圆在:直线x=200,y=200,x=200+100,y=200+100所划矩形区域内
Me.CreateGraphics.FillEllipse(New SolidBrush(Color.Orange), 200, 200, 100, 100)
'绘制一个空心圆,该圆在:直线x=200,y=200,x=200+100,y=200+100所划矩形区域内
Me.CreateGraphics.DrawEllipse(New Pen(Color.Black), 200, 200, 100, 100)
文章标题:vb.net照片黑白 vb设置图片框背景颜色
文章转载:http://hbruida.cn/article/dogepds.html