如何使用 VB6 将 PNG(图像)文件打开为 RGB 数组或 R、G、B 数组

发布于 2024-07-07 19:20:17 字数 152 浏览 2 评论 0原文

如何用VB6打开PNG格式的图像文件? 理想情况下,我(即我的客户)希望打开 PNG 文件并将其放入单独的 R(ed)、G(reen) 和 B(lue) 数组中。

VB6 不是我选择的工具(因为缺乏知识),如果有人能为我指明 VB6 解决方案的正确方向,我会很高兴。

How can one open a PNG formatted image file with VB6? Ideally, I (that is my customer) would like to have the PNG file open and placed into seperate R(ed), G(reen) and B(lue) arrays.

VB6 is not my tool of choice (for lack of knowledge) and I be thrilled if some one could point me in the right direction for a VB6 solution.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蓬勃野心 2024-07-14 19:20:17

您可以尝试开源 FreeImage 项目

You could try the open source FreeImage project.

空气里的味道 2024-07-14 19:20:17
'1 form with :
'    1 picturebox : name=Picture1
'    1 commandbutton : name=Command1
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 Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, ByRef lpObject As Any) As Long
Private Declare Function GetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, ByRef lpBits As Any) As Long
Private Declare Function SetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, ByRef lpBits As Any) As Long

Private mbmpBits() As Byte
Private mudtBmp As BITMAP

Private Sub Command1_Click()
  ShowRed
'  ShowGreen
'  ShowBlue
End Sub

Private Sub Form_Load()
  Picture1.Picture = LoadPicture("c:\temp\pic.bmp")
End Sub

Private Sub Form_Unload(Cancel As Integer)
  Set Form1 = Nothing
End Sub

Private Sub ShowRed()
  Dim lngX As Long, lngY As Long
  ReadBits
  For lngX = 0 To mudtBmp.bmWidth - 1
    For lngY = 0 To mudtBmp.bmHeight - 1
      mbmpBits(0, lngX, lngY) = 0
      mbmpBits(1, lngX, lngY) = 0
    Next lngY
  Next lngX
  ShowBits
End Sub

Private Sub ShowGreen()
  Dim lngX As Long, lngY As Long
  ReadBits
  For lngX = 0 To mudtBmp.bmWidth - 1
    For lngY = 0 To mudtBmp.bmHeight - 1
      mbmpBits(0, lngX, lngY) = 0
      mbmpBits(2, lngX, lngY) = 0
    Next lngY
  Next lngX
  ShowBits
End Sub

Private Sub ShowBlue()
  Dim lngX As Long, lngY As Long
  ReadBits
  For lngX = 0 To mudtBmp.bmWidth - 1
    For lngY = 0 To mudtBmp.bmHeight - 1
      mbmpBits(1, lngX, lngY) = 0
      mbmpBits(2, lngX, lngY) = 0
    Next lngY
  Next lngX
  ShowBits
End Sub

Private Sub ReadBits()
  GetObject Picture1.Picture.Handle, Len(mudtBmp), mudtBmp
  With mudtBmp
    ReDim mbmpBits(0 To (.bmBitsPixel \ 8) - 1, 0 To .bmWidth - 1, 0 To .bmHeight - 1) As Byte
    GetBitmapBits Picture1.Picture.Handle, .bmWidthBytes * .bmHeight, mbmpBits(0, 0, 0)
  End With 'mudtBmp
End Sub

Private Sub ShowBits()
  SetBitmapBits Picture1.Picture.Handle, mudtBmp.bmWidthBytes * mudtBmp.bmHeight, mbmpBits(0, 0, 0)
  Erase mbmpBits
  Picture1.Refresh
End Sub
'1 form with :
'    1 picturebox : name=Picture1
'    1 commandbutton : name=Command1
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 Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, ByRef lpObject As Any) As Long
Private Declare Function GetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, ByRef lpBits As Any) As Long
Private Declare Function SetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, ByRef lpBits As Any) As Long

Private mbmpBits() As Byte
Private mudtBmp As BITMAP

Private Sub Command1_Click()
  ShowRed
'  ShowGreen
'  ShowBlue
End Sub

Private Sub Form_Load()
  Picture1.Picture = LoadPicture("c:\temp\pic.bmp")
End Sub

Private Sub Form_Unload(Cancel As Integer)
  Set Form1 = Nothing
End Sub

Private Sub ShowRed()
  Dim lngX As Long, lngY As Long
  ReadBits
  For lngX = 0 To mudtBmp.bmWidth - 1
    For lngY = 0 To mudtBmp.bmHeight - 1
      mbmpBits(0, lngX, lngY) = 0
      mbmpBits(1, lngX, lngY) = 0
    Next lngY
  Next lngX
  ShowBits
End Sub

Private Sub ShowGreen()
  Dim lngX As Long, lngY As Long
  ReadBits
  For lngX = 0 To mudtBmp.bmWidth - 1
    For lngY = 0 To mudtBmp.bmHeight - 1
      mbmpBits(0, lngX, lngY) = 0
      mbmpBits(2, lngX, lngY) = 0
    Next lngY
  Next lngX
  ShowBits
End Sub

Private Sub ShowBlue()
  Dim lngX As Long, lngY As Long
  ReadBits
  For lngX = 0 To mudtBmp.bmWidth - 1
    For lngY = 0 To mudtBmp.bmHeight - 1
      mbmpBits(1, lngX, lngY) = 0
      mbmpBits(2, lngX, lngY) = 0
    Next lngY
  Next lngX
  ShowBits
End Sub

Private Sub ReadBits()
  GetObject Picture1.Picture.Handle, Len(mudtBmp), mudtBmp
  With mudtBmp
    ReDim mbmpBits(0 To (.bmBitsPixel \ 8) - 1, 0 To .bmWidth - 1, 0 To .bmHeight - 1) As Byte
    GetBitmapBits Picture1.Picture.Handle, .bmWidthBytes * .bmHeight, mbmpBits(0, 0, 0)
  End With 'mudtBmp
End Sub

Private Sub ShowBits()
  SetBitmapBits Picture1.Picture.Handle, mudtBmp.bmWidthBytes * mudtBmp.bmHeight, mbmpBits(0, 0, 0)
  Erase mbmpBits
  Picture1.Refresh
End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文