VBA bmp

Option Explicit

Public Type RGBTRIPLE
    rgbBlue As Byte
    rgbGreen As Byte
    rgbRed As Byte
End Type

Private Type BITMAPFILEHEADER
    bfType As String * 2
    bfSize As Long
    bfReserved1 As Integer
    bfReserved2 As Integer
    bjOffBits As Long
End Type
Private Type BitmapInfoHeader
    biSize As Long
    biWidth As Long
    biHeight As Long
    biPlanes As Integer
    biBitCount As Integer
    biCompression As Long
    biSizeImaze As Long
    biXPixPerMeter As Long
    biYPixPerMeter As Long
    biClrUsed As Long
    biClrImporant As Long
End Type

Public bjHeader As BITMAPFILEHEADER
Public biHeader As BitmapInfoHeader

Public Function ReadBitmap(strFileName As String) As RGBTRIPLE()
    Dim i As Long
    Dim j As Long
    Dim n As Long
    Dim intFileNumber As Integer
    Dim lngColors As Long
    Dim rgbData() As RGBTRIPLE
    Dim rgbTemp As RGBTRIPLE
    Dim bytTemp As Byte
    
    intFileNumber = FreeFile()
    Open strFileName For Binary As intFileNumber
        Get intFileNumber, , bjHeader
        Get intFileNumber, , biHeader
        
        ReDim rgbData(0 To biHeader.biHeight - 1, 0 To biHeader.biWidth - 1) As RGBTRIPLE
        n = (4 - (-(Int(-biHeader.biWidth * (biHeader.biBitCount / 8))) Mod 4)) Mod 4
        lngColors = IIf(biHeader.biClrUsed = 0, 2 ^ biHeader.biBitCount, biHeader.biClrUsed)
        
        
        For i = UBound(rgbData, 1) To 0 Step -1
            For j = 0 To UBound(rgbData, 2)
                Get intFileNumber, , rgbData(i, j)
            Next
            For j = 1 To n
                Get intFileNumber, , bytTemp
            Next
        Next
    Close
    
    ReadBitmap = rgbData
End Function
Public Sub WriteBitmapTurn90(strFileName As String, rgbData() As RGBTRIPLE)
    Dim i As Long
    Dim j As Long
    Dim n As Long
    Dim lngWidth As Long
    Dim lngHeight As Long
    Dim intFileNumber As Integer
    Dim bytTemp As Byte
    
    lngHeight = UBound(rgbData, 1) + 1
    lngWidth = UBound(rgbData, 2) + 1
    n = (4 - (lngHeight * 3 Mod 4)) Mod 4
    
    With bjHeader
        .bfSize = Len(bjHeader) + Len(biHeader) + 3 * lngHeight * lngWidth + n * lngWidth
        .bjOffBits = Len(bjHeader) + Len(biHeader)
    End With
    With biHeader
        .biWidth = lngHeight
        .biHeight = lngWidth
        .biSizeImaze = bjHeader.bfSize - Len(bjHeader) - Len(biHeader)
    End With
    
    If Len(Dir(strFileName)) Then
        Kill strFileName
    End If
    
    intFileNumber = FreeFile()
    Open strFileName For Binary As intFileNumber
        Put intFileNumber, , bjHeader
        Put intFileNumber, , biHeader
        
        For i = lngWidth - 1 To 0 Step -1
            For j = 0 To lngHeight - 1
                Put intFileNumber, , rgbData(j, i)
            Next
            For j = 1 To n
                Put intFileNumber, , bytTemp
            Next
        Next
    Close
End Sub

-----------------------------------------------------------

Sub Main()
    'ファイル選択ダイアログでファイルを指定
    Dim vFilePath As Variant
    Dim fileName As String
    Dim rgbData() As RGBTRIPLE
    
    vFilePath = Application.GetOpenFilename
    If vFilePath = False Then
        End
    End If
 
    'ファイルサイズが0バイトの場合は処理終了
    Dim nFileLen As Long
    nFileLen = FileLen(vFilePath)
    If nFileLen = 0 Then
        End
    End If
        
    fileName = vFilePath
    rgbData = ReadBitmap(fileName)
    Call WriteBitmapTurn90("2.bmp", rgbData)
 
End Sub

Private Sub CommandButton1_Click()
  Call Main
End Sub

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ArcMap VBA 可以通过控件来实现用户界面的设计和交互。以下是一些常见的控件及其用途: 1. CommandButton:用于执行特定的命令或操作,如打开文件、保存数据等。 2. Label:用于显示文本或标签,如标题、说明等。 3. TextBox:用于接收用户输入的文本。 4. ComboBox:用于提供下拉菜单选择项,如选择不同的图层。 5. ListBox:用于提供多个选择项,如选择多个要素。 6. CheckBox:用于提供二选一的选择项,如是否显示标注。 7. OptionButton:用于提供多选一的选择项,如选择符号类型。 在 ArcMap VBA 中,可以通过工具箱(Toolbox)中的“用户界面”工具栏添加控件,也可以通过代码动态地创建控件。例如,以下代码创建一个 CommandButton 控件并添加到当前的工具栏中: ``` Sub AddButtonToToolbar() Dim pCmdItem As ICommandItem Dim pUID As New UID Set pUID = New UID pUID.Value = "esriArcMapUI.ZoomInTool" Set pCmdItem = Application.Document.CommandBars.Find(pUID) Dim pButton As New ESRI.ArcGIS.Framework.CommandBarButton Set pButton = pCmdItem.CommandBar.Controls.Add( _ esriCmdType.esriCmdTypeGeneric, _ , _ esriToolbarControlVisibility.esriTCV_ALWAYS) With pButton .Caption = "Custom Button" .Style = esriCommandStyles.esriCommandStyleIconAndText .Bitmap = LoadPicture("C:\MyIcon.bmp") .Width = 80 .OnClick = "CustomButton_OnClick" End With End Sub ``` 这个例子中,首先找到了一个 ZoomInTool 命令,然后创建了一个 CommandBarButton 控件,并将其添加到命令条中。在设置控件的属性时,可以指定控件的图标、宽度和点击事件等。这样就可以在 ArcMap 中自定义一个功能按钮,以执行自己的操作了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值