Chishin Blog 千里之堤毁于蚁穴 —— 小歆
发表于 2012-11-28 | | 软件源码
   Public Function ResizePicture(ByVal sourceImage As Bitmap, _
                ByVal newSize As Size) As Bitmap '调整图片大小(图片源,新尺寸)

        Dim Result_image As New Bitmap(sourceImage, newSize.Width, newSize.Height)
        Dim Gr As Graphics

        Gr = Graphics.FromImage(Result_image)
        Gr.DrawImage(Result_image, 0, 0, newSize.Width, newSize.Height)

        Return Result_image
    End Function

    Public Function CropBitmap(ByVal inputBmp As Bitmap, _
                ByVal cropRectangle As Rectangle) As Bitmap '裁剪位图(输出,矩形)
        Dim newBmp As New Bitmap(cropRectangle.Width, _
                 cropRectangle.Height, _
                 System.Drawing.Imaging.PixelFormat.Format24bppRgb) 'Graphics.FromImage 
                                                'doesn't like Indexed pixel format

        Dim newBmpGraphics As Graphics = Graphics.FromImage(newBmp)

        newBmpGraphics.DrawImage(inputBmp, _
              New Rectangle(0, 0, cropRectangle.Width, cropRectangle.Height), _
                cropRectangle, _

        'Return the bitmap

        'newBmp will have a RawFormat of MemoryBmp because it was created
        'from scratch instead of being based on inputBmp.  Since it is inconvenient
        'for the returned version of a bitmap to be of a different format, now convert
        'the scaled bitmap to the format of the source bitmap
        Return newBmp
    End Function