准备做个有难度的工程,TIF图像自动去污点,自动校正倾斜,欢迎进来探讨
目前准备做一个tiff图像自动整理的程序,图像性质是扫描的西文期刊
功能包括
1、计算出倾斜多少度,并校正
2、清除行之间的污点
3、清除版心周围空白处的污点
目前初步确定ImgEdit和Picture两个控件结合使用。
使用Picture控件的Point函数来读像素,通过像素值判断倾斜度和污点
难点就是各种算法,例如倾斜度是纵向读取判断还是横向读取判断,误点大小如何区别i或者j上面的点。
欢迎大家前来讨论,如果有相同的经验,请不吝赐教。
同时我也会把我最新的进展写在这个帖子里面。
[解决办法]
http://tech.acnow.net/Html/Program/VB/GUI/2005-8/7/225104251.shtml
这上面有你需要的完整代码
[解决办法]
设置picture1的scalemode为3
Private Type BITMAPINFOHEADER '40 bytes
biSize As Long 'BITMAPINFOHEADER结构的大小
biWidth As Long
biHeight As Long
biPlanes As Integer '设备的为平面数,现在都是1
biBitCount As Integer '图像的颜色位图
biCompression As Long '压缩方式
biSizeImage As Long '实际的位图数据所占字节
biXPelsPerMeter As Long '目标设备的水平分辨率
biYPelsPerMeter As Long '目标设备的垂直分辨率
biClrUsed As Long '使用的颜色数
biClrImportant As Long '重要的颜色数。如果该项为0,表示所有颜色都是重要的
End Type
Private Type RGBQUAD '只有bibitcount为1,2,4时才有调色板
Blue As Byte '蓝色分量
Green As Byte '绿色分量
Red As Byte '红色分量
Reserved As Byte '保留值
End Type
Private Type BITMAPINFO
bmiHeader As BITMAPINFOHEADER
bmiColors As RGBQUAD
End Type
Private Declare Function GetDIBits Lib "gdi32 " (ByVal aHDC As Long, ByVal hBitmap As Long, ByVal nStartScan As Long, ByVal nNumScans As Long, lpBits As Any, lpBI As BITMAPINFO, ByVal wUsage As Long) As Long
Private Declare Function SetDIBits Lib "gdi32 " (ByVal hdc As Long, ByVal hBitmap As Long, ByVal nStartScan As Long, ByVal nNumScans As Long, lpBits As Any, lpBI As BITMAPINFO, ByVal wUsage As Long) As Long
Private Sub GetPicData(Pic As PictureBox, PicData() As RGBQUAD) '读取位图数据
Dim DIBInfo As BITMAPINFO
With DIBInfo.bmiHeader
.biSize = Len(DIBInfo.bmiHeader)
.biWidth = Pic.ScaleWidth
.biHeight = -Pic.ScaleHeight '从下往上扫描
.biPlanes = 1
.biBitCount = 32 '32位位图,默认情况下Windows不会处理最高8位,可以将它作为自己的Alpha通道
.biCompression = BI_RGB '无压缩
End With
ReDim PicData(1 To Pic.ScaleWidth, 1 To Pic.ScaleHeight) As RGBQUAD
GetDIBits Pic.hdc, Pic.Image, 0, Pic.ScaleHeight, PicData(1, 1), DIBInfo, DIB_RGB_COLORS
End Sub
Private Sub ShowPic(Pic As PictureBox, PicData() As RGBQUAD) '显示位图
Dim DIBInfo As BITMAPINFO
With DIBInfo.bmiHeader
.biSize = Len(DIBInfo.bmiHeader)
.biWidth = Pic.ScaleWidth
.biHeight = -Pic.ScaleHeight '从下往上扫描
.biPlanes = 1
.biBitCount = 32 '32位位图,默认情况下Windows不会处理最高8位,可以将它作为自己的Alpha通道
.biCompression = BI_RGB '无压缩
End With
SetDIBits Pic.hdc, Pic.Image, 0, Pic.ScaleHeight, PicData(1, 1), DIBInfo, DIB_RGB_COLORS
Pic.Refresh
End Sub
Private Sub Command1_Click()
Dim PicData() As RGBQUAD
GetPicData Picture1, PicData
Dim i As Integer, j As Integer
For i = 1 To Picture1.ScaleWidth
For j = 1 To Picture1.ScaleHeight
PicData(i, j).Red = 255 - PicData(i, j).Red
PicData(i, j).Green = 255 - PicData(i, j).Green
PicData(i, j).Blue = 255 - PicData(i, j).Blue
Next
Next
ShowPic Picture1, PicData
End Sub