VB.NET最为一款功能强大的.NET编程语言,其实用价值在开发领域是公认的。我们在这里将会为大家介绍一下有关VB.NET图像操作的相关实现技巧,从另一角度去慢慢体会其功能应用的简便及强大性。 #t#

公司主营业务:成都做网站、成都网站建设、成都外贸网站建设、移动网站开发等业务。帮助企业客户真正实现互联网宣传,提高企业的竞争能力。创新互联是一支青春激扬、勤奋敬业、活力青春激扬、勤奋敬业、活力澎湃、和谐高效的团队。公司秉承以“开放、自由、严谨、自律”为核心的企业文化,感谢他们对我们的高要求,感谢他们从不同领域给我们带来的挑战,让我们激情的团队有机会用头脑与智慧不断的给客户带来惊喜。创新互联推出平凉免费做网站回馈大家。
慢速,这是以像素点操作为代表:
快速,以内存指针操作为代表,这是VB.NET图像操作中最快的方法
- Public Function fan_fast(ByVal
 
inputImage As Image) As Image- Dim R As Byte, G As Byte, B As
 
Byte, Col As Byte- Dim Width As Integer, Height
 
As Integer- Dim Pic As Bitmap = New
 
Bitmap(inputImage)- Width = Pic.Width :
 
Height = Pic.Height- Dim rect As New Rectangle(0, 0,
 
Width, Height)- Dim bmpData As BitmapData =
 
Pic.LockBits(rect, ImageLockMode.
ReadWrite, Pic.PixelFormat)- Dim ptr As IntPtr = bmpData.Scan0
 
'得到***个像素的指针- '数组操作()
 - Dim bytes As Integer =
 
bmpData.Stride * Height- Dim rgbValues(bytes - 1) As Byte
 - Marshal.Copy(ptr, rgbValues, 0, bytes)
 
'将内存块复制到数组,这是该方法的关键- For k As Integer = 0 To
 
rgbValues.Length - 4 Step 4- B = CByte(255 - rgbValues(k))
 - G = CByte(255 - rgbValues(k + 1))
 - R = CByte(255 - rgbValues(k + 2))
 - rgbValues(k) = B
 - rgbValues(k + 1) = G
 - rgbValues(k + 2) = R
 - Next
 - Marshal.Copy(rgbValues, 0, ptr, bytes)
 
'再将数组复制到内存块- '数组操作结束
 - Pic.UnlockBits(bmpData)
 - Return Pic
 - End Function
 - 还有一种以C#中的非安全代码 指针操作
 - public Bitmap fan_fast2(Bitmap b)
 - {
 - int width = b.Width;
 - int height = b.Height;
 - BitmapData data = b.LockBits
 
(new Rectangle(0, 0, width, height),
ImageLockMode.ReadWrite,
PixelFormat.Format32bppArgb);- unsafe
 - {
 - byte* p = (byte*)data.Scan0;
 - int offset = data.Stride - width * 4;
 
for (int y = 0; y < height; y++)- {
 - for (int x = 0; x < width; x++)
 - {
 - p[2] ^= 0xFF;
 - p[1] ^= 0xFF;
 - p[0] ^= 0xFF;
 - p += 4;
 - }
 - p += offset;
 - }
 - b.UnlockBits(data);
 - return b;
 - }
 - }
 
如果要改造成vb.net,就是这样,VB.NET图像操作的速度大约比数组加指针慢2-3倍
- Public Function fan_fast2(ByVal
 
inputImage As Image) As Image- Dim R As Byte, G As Byte,
 
B As Byte, Col As Byte- Dim Width As Integer,
 
Height As Integer- Dim Pic As Bitmap =
 
New Bitmap(inputImage)- Width = Pic.Width : Height =
 
Pic.Height- Dim rect As New Rectangle
 
(0, 0, Width, Height)- Dim bmpData As BitmapData =
 
Pic.LockBits(rect, ImageLockMode.
ReadWrite, Pic.PixelFormat)- Dim ptr As IntPtr = bmpData.Scan0
 
'得到***个像素的指针- ''指针操作 在这种模式下,比数组操作要慢2-3倍
 - Dim offset As Integer = bmpData.
 
Stride - bmpData.Width * 4- For j As Integer = 0 To Height - 1
 - For i As Integer = 0 To Width - 1
 - B = CByte(255 - Marshal.ReadByte(ptr))
 - G = CByte(255 - Marshal.ReadByte(ptr, 1))
 - R = CByte(255 - Marshal.ReadByte(ptr, 2))
 - Marshal.WriteByte(ptr, 0, B)
 - Marshal.WriteByte(ptr, 1, G)
 - Marshal.WriteByte(ptr, 2, R)
 - ptr = CType(ptr.ToInt32 + 4, IntPtr)
 - Next
 - ptr = CType(ptr.ToInt32 +
 
offset, IntPtr)- Next
 - ''指针操作结束
 - Pic.UnlockBits(bmpData)
 - Return Pic
 - End Function
 
VB.NET图像操作的相关操作方法就为大家介绍到这里
                网页题目:迅速实现VB.NET图像操作方法简介
                
                本文来源:http://www.csdahua.cn/qtweb/news22/545872.html
            
网站建设、网络推广公司-快上网,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 快上网