VB改变图片大小的函数

小歆13年前软件源码03217
   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)
        Gr.Save()

        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, _
                GraphicsUnit.Pixel)

        'Return the bitmap
        newBmpGraphics.Dispose()

        '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        

相关文章

用VB快速读取TextBox第N行的数据

TextBox 是以 vbCr+vbLf 为分行符号, 如果我们要逐一读取 TextBox 每一行, 无非是寻找 vbCr+vbLf 的所在位置, 然后取出每一行的字串, 不过这个方法不快,而且...

VB代码优化的六条军规

       在优化程序代码大小的诸多技术中,大多包括从代码中删除不必要的元素。在编译应用程序时,Visual Basic自动删除某些元素。而标识符名称、...

vb中Msgbox函数的用法

VB中的Msgbox函数,可实现弹出窗口 作用:在对话框中显示消息,等待用户单击按钮,并返回一个 Integer 告诉用户单击哪一个按钮。 语法: MsgBox...

网络理财收益查询工具2.1.jpg

[小歆][网络理财收益查询工具][V2.1][2014.2.14]

网络理财收益查询工具V2.1 正式版 介绍:     网络理财收益查询工具原名为余额宝收...

【详解】VB6.0下用MSComm控件实现串口通信

VB6.0 下用 MSComm 控件实现串口通信 MSComm 控件通过串行端口传输和接收数据,为应用程序提供串行通讯功能 下...

VB 调用摄像头拍照,并保存图片...

VB 调用摄像头拍照 1、首先创建一个标准EXE工程 2、在窗体代码中加入如下必需的API及一个拍照的自定义函数 Private...

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。