本人想要用一个Picture控件放一张照片。
可是照片有大有小,怎样让这些大小不一的照片按的我控件大小等比例放大或缩小。
请详细说明实现过程
如有源代码那更好。
[email protected]

解决方案 »

  1.   

    建议用image控件stretch属性为True    会自动适应控件大小
      

  2.   

    照你的意思最好是用image控件,Image1.Stretch = True
      

  3.   

    image控件  把Image的属性Stretch 设为 True
      

  4.   

    image控件  把Image的属性Stretch 设为 True
      

  5.   

    image控件不会应照片太大大小也会发生改变吗?
      

  6.   

    等比例缩放是不是按照照片的大小等比例?
    如果简单的话就按照上面大侠们的方法吧.
    如果想复杂一些就可以直接使用API函数
    StretchBlt
    一个例子,放大图片同理
    Private Function smallPic()  '将图片缩小至缩略图
    Dim PicErr As Long
    If Picture1.Width <= Picture2.Width And Picture1.Height <= Picture2.Height Then
       '显示原有大小
       PicErr = BitBlt(Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, Picture2.hdc, 0, 0, SRCCOPY)
    Else
       '将图片缩小
       Dim C_Width, C_Height As Integer
       If Picture1.Width > Picture1.Height Then   '缩小宽度
          '计算比例
          C_Width = Picture2.ScaleWidth
          C_Height = C_Width * (Picture1.ScaleHeight / Picture1.ScaleWidth)
       Else
          '计算比例
          C_Height = Picture2.ScaleHeight
          C_Width = C_Height * (Picture1.ScaleWidth / Picture1.ScaleHeight)
       End If
       PicErr = StretchBlt(Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, Picture2.hdc, 0, 0, C_Width, C_Height, SRCCOPY)
    End If
    End Function
      

  7.   

    1.用Frame做容器
    2.在Frame上放一个Image控件,主要要灵活运用Image的Stretch属性.载入图片前设为TRUE先获取宽和高,再FALSE设置需要的宽和高。
    3.与容器做比较再定位.
      

  8.   

    Picture2 = LoadPicture(FileName)
        'Picture1.AutoRedraw = True    '判断 Picture2 图片大小,调整后,打印到 Picture1
        Dim sHW1 As Single
        sHW1 = Picture1.Height / Picture1.Width
        
        If Picture2.Height / Picture2.Width > sHW1 Then
            '如果源图片高与宽比例大于需求比例,取原宽度和高度的中间区域
            Picture1.PaintPicture Picture2.Picture, 0, 0, Picture1.Width, Picture1.Height, _
                0, (Picture2.Height - Picture2.Width * sHW1) / 2, Picture2.Width, Picture2.Width * sHW1
        Else
            '否则,取宽度的中间区域和原高度
           Picture1.PaintPicture Picture2.Picture, 0, 0, Picture1.Width, Picture1.Height, _
                (Picture2.Width - Picture2.Height / sHW1) / 2, 0, Picture2.Height / sHW1, Picture2.Height
        End If
        Set Picture2.Picture = LoadPicture("")