VBGood网站全文搜索 Google

搜索VBGood全站网页(全文搜索)

VB爱好者乐园(VBGood)

 找回密码
 立即注册
搜索
查看: 38815|回复: 116

为即将发布的cimage图象图形处理类征求意见!

[复制链接]
 楼主| 发表于 2007-4-27 20:53:55 | 显示全部楼层 |阅读模式
   cimage类是采用Visual Basic 6.0编写的一款图象和图形处理的类库(以图像处理为主),全面支持1位色\4位色\8位色\24位色\32位色(BMP格式),非BMP格式通过VB的stdpicture对象转换后进行处理,采用模拟指针和DIBSECION相结合的技术,使处理速度大大提高,大部分绝对不会低于VC的90%,部分可能会优于VC.结合自行开发的canvas控件可以很好的显示和处理图象.现把主要功能介绍如下:
   1 创建和销毁函数:
Function Create(Width As Long, Height As Long, [Bits As Integer = 32], [BackColor As Long]) As Boolean
创建新的Dib对象,可以选择位数(目前虽然可选位数,但在外部调用的时候有意义的只有32位\24位\8位)以及背景色.

Function CreateFromFile(Filename As String) As Boolean
从文件直接创建DIB对象,会检查文件是否存在以及是否是图片文件.如果为BMP文件,则分析其是几位色.如果为其他非BMP但VB支持的图片文件,则自动转换为32色的处理.这个函数最常用,自我觉得支持的比较全面了.考虑到了调色板的设置.

Function CreateFromStdPicture(Picture As StdPicture, [dwRop As RasterOpConstants = 13369376]) As Boolean\
从StdPicture对象创建DIB对象,32位的了.最后一个参数是光栅操作,一般为vbsrccopy.
  
Function CreateFromStdPictureEx(Picture As StdPicture, [SrcX As Long], [SrcY As Long], [SrcW As Long], [SrcH As Long], [dwRop As RasterOpConstants = vbSrcCopy]) As Boolean
扩展的从StdPicture对象创建DIB对象,32位的了.包括一些区域参数

Function CreateFromDC(hSrcDC As Long, [X As Long], [Y As Long], [Width As Long], [Height As Long], [SrcX As Long], [SrcY As Long], [dwRop As RasterOpConstants = vbSrcCopy]) As Boolean
从设备场景创建DIB对象,会自动分析设备场景的水平和垂直可见区域,对于不可见区域不予以考虑(即使考虑也是黑色的一片,似乎没有意义).
Function CreateFromClipBoard() As Boolean
从剪贴板创建DIB对象,会分析剪贴班是否含有有效数据.

以上函数返回值表示了DIB对象是否创建成功.

Sub Destroy()
销毁DIB对象及相关资源.
 楼主| 发表于 2007-4-27 21:01:07 | 显示全部楼层
部分属性:
Property BackColor As Long
设置背景色
Property ColorBit As Long
DIB对象的颜色位数
Property DataPtr As Long
DIB数据存放的首位地址
Property ForeColor As Long
前景色
Property hDC As Long
设备场景
Property Height As Long
DIB的高度
Property ImageDataSize As Long
图象数据的总大小
Property ImageMode As ImageModeEnum
图象的位数
Property TextAlignment As TextAlignment
文字对齐方式
Property TextHeight(Str As String) As Long
指定文字的高度
Property TextWidth(Str As String) As Long
指定文字的宽度
Property Width As Long
DIB的宽度
Property WidthBytes As Long
DIB对象的扫描的行的宽度

主要是图形处理方面的属性,图形处理现在还不完善!
回复 支持 反对

使用道具 举报

 楼主| 发表于 2007-4-27 21:15:52 | 显示全部楼层
切换图象模式:
处理速度以1024*768的图象为准,机器配置256内存,塞样2.4G,XP系统
Function ChangeToBitmapMode([Method As Dither = 1]) As Boolean
转换成BitmapMode模式,既黑和白,提供Bayer\ ErrorDiffuse\Floyd_Steinberg\ ZYL910\None(bitblt)几种抖动方法.原始图象必须是灰度模式,大概50ms

Function ChangeToGreyMode() As Boolean
转换成灰度模式(8位),原始图象可为32位,24位,8位\4位索引色.最慢32ms

Function ChangeToIndexMode(ColorTable() As RGBQUAD, [Dither As Boolean = False]) As Boolean
通过指定的调色半转换成索引色.,原始图象可为32色\24色\灰度图象.
如何得到调色板,可参考GetSpecialColorTable函数. 时间估计:100ms

Function ChangeToRGBMode([NewBits As Integer = 32]) As Boolean
转换为RGB模式,可选位数(24\32)   16ms
回复 支持 反对

使用道具 举报

 楼主| 发表于 2007-4-27 21:27:59 | 显示全部楼层
常用非图象图形处理方法:
Function Clone() As Cimage
clone一个新的完全一样的对象.包括选入其中的所有资源
Function CopyDataToCImage(Image As Cimage) As Boolean
仅复制DIB图象数据到指定的对象,指定的对象必须和原来的具有同样的颜色深度和大小.
Function CopyToClipBoard([Cut As Boolean = False]) As Boolean
把数据复制到剪贴板,如果cut为真的,则同时删除原对象中的数据.
Sub FreePoint(DataArrPtr As Long, pDataArrPtr As Long, OldArrPtr As Long, OldpArrPtr As Long)
模拟指针中的函数,对应MakePoint,学习自zyl910
Sub MakePoint(DataArrPtr As Long, pDataArrPtr As Long, OldArrPtr As Long, OldpArrPtr As Long)
Function GetDCMaxX(hDC As Long) As Long
得到DC中水平方向的可见范围

Function GetDCMaxY(hDC As Long) As Long
得到DC中垂直方向的可见范围

Function GetNearestColor(ColorTable() As RGBQUAD, Color As Long) As Long
得到指定的颜色与指定的颜色表中颜色最接近的颜色.

Sub GetRGB(Color As Long, Red As Long, Green As Long, Blue As Long)
得到指定颜色的R\G\B分量

Sub RGBToHLS(Red As Byte, Green As Byte, Blue As Byte, Hue As Single, Lightness As Single, Saturation As Single)
RGB模型到HLS模型,比网上流行的代码速度做了优化.

Sub HLStoRGB(Hue As Single, Lightness As Single, Saturation As Single, Red As Byte, Green As Byte, Blue As Byte)
HLS模型到RGB模型

Function UsedColorsAmount() As Long
得到图片中使用的不同颜色个数
回复 支持 反对

使用道具 举报

 楼主| 发表于 2007-4-27 21:30:33 | 显示全部楼层

输出:

输出:
Function OutPut(OutDC As Long, [X As Long], [Y As Long], [Width As Long], [Height As Long], [SrcX As Long], [SrcY As Long], [dwRop As RasterOpConstants = vbSrcCopy]) As Boolean
输出到DC

Function OutPutEx(hWnd As Long, [X As Long], [Y As Long], [Width As Long], [Height As Long], [SrcX As Long], [SrcY As Long], [dwRop As RasterOpConstants = vbSrcCopy]) As Boolean

输出到指定句柄的对象中

Function StretchOutPut(hOutDC As Long, [X As Long], [Y As Long], [W As Long], [H As Long], [SrcX As Long], [SrcY As Long], [srcWidth As Long], [srcHeight As Long], [dwRop As RasterOpConstants = vbSrcCopy], [StretchMode As Long]) As Boolean
缩放输出,用在放大和缩小上.
回复 支持 反对

使用道具 举报

发表于 2007-4-27 21:30:40 | 显示全部楼层


支持,拿个小板凳
回复 支持 反对

使用道具 举报

 楼主| 发表于 2007-4-27 21:38:08 | 显示全部楼层
模拟PS中的调整函数:
Function AutoLightness() As Boolean 
自动亮度     200ms
Function AdjustBrightness(Factor As Long) As Boolean  15ms
Function Desaturate() As Boolean   去色  15ms
Function Equalize() As Boolean    色调均化  32ms
Function Exposal() As Boolean    暴光效果  32ms
Function Invert() As Boolean    反色    15ms /0 ms

即将提供自动颜色,自动色阶,色阶,曲线,通道混合器,渐变隐射,阀值功能(getdibbits版本的以写好,还没该为模拟指针版本的);这些函数的速度都在15ms左右,可以实时调节与显示.
回复 支持 反对

使用道具 举报

 楼主| 发表于 2007-4-27 21:41:48 | 显示全部楼层
ps的画布调整部分:
Function Rotate180() As Boolean  速度15ms
Function Rotate270() As Boolean
Function Rotate90() As Boolean
Function Rotate() As Boolean    '任意角度旋转,支持背景色,支持抗锯齿. 速度视旋转角度而定,但不超过250ms.
Function FlipHorizontal() As Boolean
Function FlipVertical() As Boolean
Function MirrorX([FromLeftToRight As Boolean = True])
Function MirrorY([FromTopToBottom As Boolean = True])
回复 支持 反对

使用道具 举报

 楼主| 发表于 2007-4-27 21:50:37 | 显示全部楼层
ps的图象大小部分:
Function Resample(NewWidth as long,NewHeight as long,.........) AS Boolean
缩放图象大小.可选4种缩放方法,双线形插值\三次立方\系统自带的stretchblt,改进自ZYL910的代码,支持多种颜色位数的图象.
回复 支持 反对

使用道具 举报

 楼主| 发表于 2007-4-27 21:54:02 | 显示全部楼层
ps中的画布调整函数
Function AdjustCanvas(Left As Long, Top As Long, Right As Long, Bottom As Long) As Boolean
速度很快,具体要看参数的值为多少.

裁减菜单
Function Crop(Left As Long, Top As Long, Width As Long, Height As Long) As Boolean
Function Fill([Color As Long]) As Boolean 填充函数,会自动更改所提供的颜色参数以使得填充后的图象符合原来的格式(针对索引色和灰度模式才有这个过程).
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

文字版|手机版|小黑屋|VBGood  

GMT+8, 2020-6-5 17:46

VB爱好者乐园(VBGood)
快速回复 返回顶部 返回列表