VB6でPNG形式の画像ファイルを開くにはどうすればよいですか? 理想的には、私 (私の顧客) は PNG ファイルを開いて、別々の R(ed)、G(reen)、および B(lue) 配列に配置したいと考えています。
VB6 は私の選択したツールではありません (知識が不足しているため)。誰かが VB6 ソリューションの正しい方向性を教えてくれたら嬉しいです。
オープン ソースのFreeImage プロジェクトを試すことができます。
'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
リンクをありがとう、流暢な VB の人ではありませんが (C と ASM のフレーバーが多い)、コードは非常に BMP 中心のようです。PNGではありません。
その場合、コードをPNG化するのは簡単なことなので、あなたがリンクを提案したと信じなければなりませんが、それにアプローチする方法はわかりません。