日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
迅速實現(xiàn)VB.NET圖像操作方法簡介

VB.NET最為一款功能強大的.NET編程語言,其實用價值在開發(fā)領(lǐng)域是公認的。我們在這里將會為大家介紹一下有關(guān)VB.NET圖像操作的相關(guān)實現(xiàn)技巧,從另一角度去慢慢體會其功能應(yīng)用的簡便及強大性。 #t#

公司主營業(yè)務(wù):成都做網(wǎng)站、成都網(wǎng)站建設(shè)、成都外貿(mào)網(wǎng)站建設(shè)、移動網(wǎng)站開發(fā)等業(yè)務(wù)。幫助企業(yè)客戶真正實現(xiàn)互聯(lián)網(wǎng)宣傳,提高企業(yè)的競爭能力。創(chuàng)新互聯(lián)是一支青春激揚、勤奮敬業(yè)、活力青春激揚、勤奮敬業(yè)、活力澎湃、和諧高效的團隊。公司秉承以“開放、自由、嚴謹、自律”為核心的企業(yè)文化,感謝他們對我們的高要求,感謝他們從不同領(lǐng)域給我們帶來的挑戰(zhàn),讓我們激情的團隊有機會用頭腦與智慧不斷的給客戶帶來驚喜。創(chuàng)新互聯(lián)推出平?jīng)雒赓M做網(wǎng)站回饋大家。

慢速,這是以像素點操作為代表:

  1. Public Function fan_slow(ByVal 
    inputImage As Image) As Image   
  2. Dim pic As Bitmap = 
    New Bitmap(inputImage)   
  3. Dim i As Integer, j As Integer   
  4. Dim R As Integer, G As 
    Integer, B As Integer   
  5. Dim Width As Integer, 
    Height As Integer   
  6. Width = Pic.Width : 
    Height = Pic.Height   
  7. Dim myColor As Color   
  8. For i = 0 To Height - 1   
  9. For j = 0 To Width - 1   
  10. R = 255-pic.GetPixel(i, j).R   
  11. G = 255-pic.GetPixel(i, j).G   
  12. B = 255-pic.GetPixel(i, j).B   
  13. myColor = Color.FromArgb(R, G, B)   
  14. pic.SetPixel(i, j, myColor)   
  15. Next   
  16. Next   
  17. Return pic   
  18. End Function  

快速,以內(nèi)存指針操作為代表,這是VB.NET圖像操作中最快的方法

 
 
 
  1. Public Function fan_fast(ByVal 
    inputImage As Image) As Image   
  2. Dim R As Byte, G As Byte, B As 
    Byte, Col As Byte   
  3. Dim Width As Integer, Height 
    As Integer   
  4. Dim Pic As Bitmap = New 
    Bitmap(inputImage)   
  5. Width = Pic.Width : 
    Height = Pic.Height   
  6. Dim rect As New Rectangle(0, 0, 
    Width, Height)   
  7. Dim bmpData As BitmapData = 
    Pic.LockBits(rect, ImageLockMode.
    ReadWrite, Pic.PixelFormat)   
  8. Dim ptr As IntPtr = bmpData.Scan0
    '得到***個像素的指針   
  9. '數(shù)組操作()   
  10. Dim bytes As Integer = 
    bmpData.Stride * Height   
  11. Dim rgbValues(bytes - 1) As Byte   
  12. Marshal.Copy(ptr, rgbValues, 0, bytes)
     '將內(nèi)存塊復(fù)制到數(shù)組,這是該方法的關(guān)鍵   
  13. For k As Integer = 0 To 
    rgbValues.Length - 4 Step 4   
  14. B = CByte(255 - rgbValues(k))   
  15. G = CByte(255 - rgbValues(k + 1))   
  16. R = CByte(255 - rgbValues(k + 2))   
  17. rgbValues(k) = B   
  18. rgbValues(k + 1) = G   
  19. rgbValues(k + 2) = R   
  20. Next   
  21. Marshal.Copy(rgbValues, 0, ptr, bytes)
    '再將數(shù)組復(fù)制到內(nèi)存塊   
  22. '數(shù)組操作結(jié)束   
  23. Pic.UnlockBits(bmpData)   
  24. Return Pic   
  25. End Function   
  26. 還有一種以C#中的非安全代碼 指針操作   
  27. public Bitmap fan_fast2(Bitmap b)   
  28. {   
  29. int width = b.Width;   
  30. int height = b.Height;   
  31. BitmapData data = b.LockBits
    (new Rectangle(0, 0, width, height), 
    ImageLockMode.ReadWrite, 
    PixelFormat.Format32bppArgb);   
  32. unsafe   
  33. {   
  34. byte* p = (byte*)data.Scan0;   
  35. int offset = data.Stride - width * 4; 
    for (int y = 0; y < height; y++)   
  36. {   
  37. for (int x = 0; x < width; x++)   
  38. {   
  39. p[2] ^= 0xFF;   
  40. p[1] ^= 0xFF;   
  41. p[0] ^= 0xFF;   
  42. p += 4;   
  43. }   
  44. p += offset;   
  45. }   
  46. b.UnlockBits(data);   
  47. return b;   
  48. }   
  49. }  

如果要改造成vb.net,就是這樣,VB.NET圖像操作的速度大約比數(shù)組加指針慢2-3倍

 
 
 
  1. Public Function fan_fast2(ByVal 
    inputImage As Image) As Image   
  2. Dim R As Byte, G As Byte, 
    B As Byte, Col As Byte   
  3. Dim Width As Integer, 
    Height As Integer   
  4. Dim Pic As Bitmap = 
    New Bitmap(inputImage)   
  5. Width = Pic.Width : Height = 
    Pic.Height   
  6. Dim rect As New Rectangle
    (0, 0, Width, Height)   
  7. Dim bmpData As BitmapData = 
    Pic.LockBits(rect, ImageLockMode.
    ReadWrite, Pic.PixelFormat)   
  8. Dim ptr As IntPtr = bmpData.Scan0
    '得到***個像素的指針   
  9. ''指針操作 在這種模式下,比數(shù)組操作要慢2-3倍   
  10. Dim offset As Integer = bmpData.
    Stride - bmpData.Width * 4   
  11. For j As Integer = 0 To Height - 1   
  12. For i As Integer = 0 To Width - 1   
  13. B = CByte(255 - Marshal.ReadByte(ptr))   
  14. G = CByte(255 - Marshal.ReadByte(ptr, 1))   
  15. R = CByte(255 - Marshal.ReadByte(ptr, 2))   
  16. Marshal.WriteByte(ptr, 0, B)   
  17. Marshal.WriteByte(ptr, 1, G)   
  18. Marshal.WriteByte(ptr, 2, R)   
  19. ptr = CType(ptr.ToInt32 + 4, IntPtr)   
  20. Next   
  21. ptr = CType(ptr.ToInt32 + 
    offset, IntPtr)   
  22. Next   
  23. ''指針操作結(jié)束   
  24. Pic.UnlockBits(bmpData)   
  25. Return Pic   
  26. End Function  

VB.NET圖像操作的相關(guān)操作方法就為大家介紹到這里


新聞標題:迅速實現(xiàn)VB.NET圖像操作方法簡介
本文來源:http://www.dlmjj.cn/article/dhppsie.html