| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1300 人关注过本帖
标题:VB图象处理
只看楼主 加入收藏
sw19830815
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2007-7-2
收藏
 问题点数:0 回复次数:11 
VB图象处理
   怎么输出图象的灰度值和根据灰度值输出图象?matlab很容易实现的,只需一个命令,不知VB行不行?
搜索更多相关主题的帖子: 图象处理 
2007-08-07 09:57
kingboy88
Rank: 1
等 级:新手上路
帖 子:24
专家分:0
注 册:2007-7-6
收藏
得分:0 
坐沙发
2007-08-09 16:11
BEARBEN
Rank: 1
等 级:新手上路
帖 子:114
专家分:0
注 册:2007-7-7
收藏
得分:0 
LZ可以研究GDI+中的函数。

我没有灰度处理的算法,但是图像处理其他的算法还是有一点的。

2007-08-11 13:18
sw19830815
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2007-7-2
收藏
得分:0 
回复:(BEARBEN)LZ可以研究GDI+中的函数。我没有灰度...
能给我传点资料吗?非常感谢!
2007-08-13 17:31
Joforn
Rank: 6Rank: 6
等 级:贵宾
威 望:23
帖 子:1242
专家分:122
注 册:2007-1-2
收藏
得分:0 

Option Explicit
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 Type MemHdc
hdc As Long
Bmp As Long
obm As Long
End Type
Private Declare Function GetObj Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long

Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) 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 Declare Function GetTickCount Lib "kernel32" () As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDest As Any, pSource As Any, ByVal dwLength As Long)
'平时常做图形处理,自己的两个公用函数也就用上了
Private Function NewMyHdc(dHdc As Long, w As Long, h As Long, Optional Bm As Long) As MemHdc
With NewMyHdc
.hdc = CreateCompatibleDC(dHdc)
If Bm = 0 Then
.Bmp = CreateCompatibleBitmap(dHdc, w, h)
Else
.Bmp = Bm
End If
.obm = SelectObject(.hdc, .Bmp)
End With
End Function

Private Function DelMyHdc(MyHdc As MemHdc, Optional nobmp As Boolean) As MemHdc
With MyHdc
If .hdc <> 0 And .obm <> 0 Then SelectObject .hdc, .obm
If nobmp = False And .Bmp <> 0 Then DeleteObject .Bmp
If .hdc <> 0 Then DeleteDC .hdc
End With
End Function

'灰度处理主函数
Public Function GrayBmp(dHdc As Long, x As Long, y As Long, w As Long, h As Long) As Long
Dim tmpdc As MemHdc
Dim i As Long, j As Long, m As Long, k As Byte, l As Long
Dim Bm As BITMAP, AllBytes As Long, LineBytes As Long
Dim dBits() As Byte
Dim dBits1() As Integer
Dim dBits2() As Long
On Error GoTo last
With tmpdc
tmpdc = NewMyHdc(dHdc, w, h)
GetObj .Bmp, Len(Bm), Bm
If Bm.bmBitsPixel < 16 Then GoTo last
BitBlt .hdc, 0, 0, w, h, dHdc, x, y, vbSrcCopy
LineBytes = Bm.bmWidthBytes
AllBytes = LineBytes * h
Select Case Bm.bmBitsPixel
Case 32
ReDim dBits2(AllBytes \ 4 - 1)
GetBitmapBits .Bmp, AllBytes, dBits2(0)
For i = 0 To AllBytes \ 4 - 1
dBits2(i) = ((dBits2(i) And &HFF00&) \ &H100) * &H10101
'dBits2(i) = (dBits2(i) And &HFF) * &H10101'用B值运算
Next
SetBitmapBits .Bmp, AllBytes, dBits2(0)
GrayBmp = 32
Case 24
ReDim dBits(AllBytes - 1)
GetBitmapBits .Bmp, AllBytes, dBits(0)
For j = 0 To h - 1
m = j * LineBytes
For i = m To m + w * 3 - 1 Step 3
dBits(i) = dBits(i + 1)
dBits(i + 2) = dBits(i)
Next
Next
SetBitmapBits .Bmp, AllBytes, dBits(0)
GrayBmp = 24
Case 16
'按565格式运算
ReDim dBits1(AllBytes \ 2 - 1)
GetBitmapBits .Bmp, AllBytes, dBits1(0)
For j = 0 To h - 1
m = j * LineBytes \ 2
For i = m To m + w - 1
l = dBits1(i) And &H7C0&
l = l * 32 + l + l \ 64
CopyMemory dBits1(i), l, 2 '这句没办法,不用CopyMemory,会溢出,低效源于此
Next
Next
SetBitmapBits .Bmp, AllBytes, dBits1(0)
GrayBmp = 16
End Select
BitBlt dHdc, x, y, w, h, .hdc, 0, 0, vbSrcCopy
End With
last:
DelMyHdc tmpdc
End Function

Private Sub Form_Load()
ScaleMode = 3
AutoRedraw = True
' Picture = LoadPicture("f:\1.jpg")
Command1.Caption = "测试"
End Sub


VB QQ群:47715789
2007-08-13 21:57
缘吇弹
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:地球
等 级:版主
威 望:43
帖 子:3038
专家分:27
注 册:2007-7-2
收藏
得分:0 
师兄好样的。好东西收藏了。

Repeat  Life=Study;Until (death);
2007-08-13 22:00
Joforn
Rank: 6Rank: 6
等 级:贵宾
威 望:23
帖 子:1242
专家分:122
注 册:2007-1-2
收藏
得分:0 
本论坛的风格就是:没见源码就哭爹喊娘,源码到手就不见人影!
说实话真不想发源码的。

VB QQ群:47715789
2007-08-13 22:33
缘吇弹
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:地球
等 级:版主
威 望:43
帖 子:3038
专家分:27
注 册:2007-7-2
收藏
得分:0 

呵呵,看来真的是打击到师兄的积极性了


Repeat  Life=Study;Until (death);
2007-08-13 22:36
Joforn
Rank: 6Rank: 6
等 级:贵宾
威 望:23
帖 子:1242
专家分:122
注 册:2007-1-2
收藏
得分:0 
以下是引用缘吇弹在2007-8-13 22:36:05的发言:

呵呵,看来真的是打击到师兄的积极性了

还打击个屁啊,没见我这两个月都不怎么发源码啦?
回帖大多都是跟个函数名,看得懂就看,看不懂也别问我,问了也不答。


VB QQ群:47715789
2007-08-13 22:39
缘吇弹
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:地球
等 级:版主
威 望:43
帖 子:3038
专家分:27
注 册:2007-7-2
收藏
得分:0 
不用怕,最起码有俺在背后支持你!

Repeat  Life=Study;Until (death);
2007-08-13 22:40
快速回复:VB图象处理
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.026346 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved