picturebox.height和picturebox.width得到的是picbox控件的大小而不是图片的大小,怎么才能得到它们呢?

解决方案 »

  1.   

    autosize,得到的就是图片的大小了
      

  2.   

    StdPicture(IPictureDisp)对象提供了Width和Height属性,当然你要用scalex和scaley两个函数转化一下单位另一个思路就是直接根据文件格式去写
      

  3.   

    好象用API GetObject也可以的,呵呵
      

  4.   

    Private Picture1 As New StdPicture
    Picture2.ScaleMode = 3 '设定成Pixel的度量单位
    Set Picture1 = LoadPicture("c:\windows\a.bmp")'stdPicture单位是Himetric所以要转换成Pixel
    height5 = ScaleY(Picture1.Height, vbHimetric, vbPixels)
    If height5 > Picture2.ScaleHeight Then
    height5 = Picture2.ScaleHeight
    End If
    width5 = ScaleX(Picture1.Width, vbHimetric, vbPixels)
    If width5 > Picture2.ScaleWidth Then
    width5 = Picture2.ScaleWidth
    End If
      

  5.   

    http://www.vchelp.net/cndevforum/subject_view.asp?subject_id=10353&forum_id=52使用getobject,得到图形后填充BITMAP结构,然后就可以得到了
    'Create a new project, add a command button and a picture box to the project, load a picture into the picture box.
    'Paste this code into Form1
    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, lpObject As Any) As Long
    Private Declare Function GetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long
    Private Declare Function SetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long
    Dim PicBits() As Byte, PicInfo As BITMAP, Cnt As Long
    Private Sub Command1_Click()
        'KPD-Team 1999
        'URL: http://www.allapi.net/
        'E-Mail: [email protected]
        'Get information (such as height and width) about the picturebox
        GetObject Picture1.Image, Len(PicInfo), PicInfo
        'reallocate storage space
        ReDim PicBits(1 To PicInfo.bmWidth * PicInfo.bmHeight * 3) As Byte
        'Copy the bitmapbits to the array
        GetBitmapBits Picture1.Image, UBound(PicBits), PicBits(1)
        'Invert the bits
        For Cnt = 1 To UBound(PicBits)
            PicBits(Cnt) = 255 - PicBits(Cnt)
        Next Cnt
        'Set the bits back to the picture
        SetBitmapBits Picture1.Image, UBound(PicBits), PicBits(1)
        'refresh
        Picture1.Refresh
    End Sub
      

  6.   

    .IMAGE 和 .picture都有width和height 属性的