Click here to Skip to main content
12,067,928 members (50,597 online)
Click here to Skip to main content

Tagged as

Stats

20K views
542 downloads
28 bookmarked
Posted

Resizing Batch Images

, 21 Feb 2008 CPOL
Resize all images in the source folder and save them in the destination folder
resizebatchimage.zip
resizeBatchImage
resizeBatchImage.suo
resizeBatchImage
bin
Release
My Project
Application.myapp
Settings.settings
Public Class clsResize

    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
        'Create a new bitmap object based on the input
        Dim newBmp As New Bitmap(cropRectangle.Width, _
                 cropRectangle.Height, _
                 System.Drawing.Imaging.PixelFormat.Format24bppRgb) 'Graphics.FromImage doesn't like Indexed pixel format

        'Create a graphics object and attach it to the bitmap
        Dim newBmpGraphics As Graphics = Graphics.FromImage(newBmp)

        'Draw the portion of the input image in the crop rectangle
        'in the graphics object
        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 it 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
End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

reza shirazi
Web Developer
Iran (Islamic Republic Of) Iran (Islamic Republic Of)
No Biography provided

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160208.1 | Last Updated 21 Feb 2008
Article Copyright 2008 by reza shirazi
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid