Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
How to change display settings: screen resolution, screen refresh rate
Adding and deleting Scheduled Tasks using NetScheduleJob API functions
Custom GDI+ class
Capturing keyboard activity of another application with the Raw Input API (VFP9)
Converting Unicode data from the Clipboard to a character string using a given code page
Enumerating data formats currently available on the clipboard
Establishing connection using the SQLDriverConnect
Winsock: sending email messages (SMTP, port 25)
Splash Screen for the VFP application
Detecting changes in connections to removable drives (VFP9)
Custom FTP Class for Visual FoxPro application
GDI+: copying to the Clipboard (a) image of active FoxPro window/form, (b) image file
How to create non-blocking Winsock server
Enumerating raw input devices attached to the system (keyboard, mouse, human interface device)
How to print a bitmap file
Bitmap Class for Visual FoxPro application
Using WM_COPYDATA for interprocess communication (VFP9)
Custom HttpRequest class (WinHTTP)
Custom HttpRequest class (WinINet)
How to activate Windows Calculator
Sending email messages with Simple MAPI
Displaying bitmap using the AlphaBlend function
How to download a file from the FTP server using FtpGetFile
Peer-to-peer LAN messenger built with Mailslot API functions
GDI+: creating scaled copy of image file

User rating: 0/10 (0 votes)
Rate this code sample:
  • ~
More code examples    Listed functions    Add comment     W32 Constants      Translate this page Printer friendly version of this code sample
Versions:
click to open
Before you begin:
The code creates source image object from an image file. It also creates empty destination bitmap object. Note that the Bitmap class is subclassed from the Image class. GDI+ flat API calls allow to use bitmap handles as if they were image handles.

Then the code uses the graphics of the destination bitmap both as a tool and canvas to draw the scaled source image on it. Finally the destination bitmap saves itself to file.

The code is based on custom GDI+ class. Download the class module first and save it in gdiplus.prg file.

Make sure the source and destination file names are valid. The source file can be in any of graphics formats supported by the GDI+: BMP, GIF, JPG, TIF, EMF... The destination file type is limited to BMP, JPG, GIF, PNG and TIFF.

See also:
  • GDI+: cropping images
  • GDI+: rotating images

  •  
    Imports System
    Imports System.IO
    Imports System.Drawing
     
    Public Class ImageResizer
        Public errorno As Integer = 0
        Public errormessage As String = ""
     
        Protected _sourcefilename As String = ""
        Protected _sourceimage As System.Drawing.Image
        Protected _resizedimage As System.Drawing.Image
     
        Public Property sourcefilename() As String
            Get
                Return _sourcefilename
            End Get
            Set(ByVal Value As String)
                ClearError()
                If Not _sourceimage Is Nothing Then
                    _sourceimage.Dispose()
                    _sourceimage = Nothing
                End If
     
                Try
                    _sourceimage = Image.FromFile(Value)
                    _sourcefilename = Value
                Catch e As Exception
                    _sourcefilename = ""
                    SetError(-1, e.Message)
                End Try
            End Set
        End Property
     
        Public ReadOnly Property sourceimage() As Image
            Get
                Return _sourceimage
            End Get
        End Property
     
        Public Sub New(Optional ByVal filename As String = "")
            If filename.Length > 0 Then sourcefilename = filename
        End Sub
     
        Protected Sub ClearError()
            SetError(0, "")
        End Sub
     
        Protected Sub SetError(ByVal n As Integer, _
            ByVal msg As String)
            errorno = n
            errormessage = msg
        End Sub
     
        Public Sub SaveResizedimage(ByVal filename As String)
            If _resizedimage Is Nothing Then
                SetError(-1, "The image has not been resized yet.")
                Return
            End If
            _resizedimage.Save(filename, Imaging.ImageFormat.Jpeg)
        End Sub
     
        Protected Function ThumbnailCallback() As Boolean
            SetError(-1, "CreateThumbnail function failed.")
            Return False
        End Function
     
        Public Sub ResizeImage(ByVal width As Integer, _
            ByVal height As Integer, Optional ByVal mode As Integer = 0)
            If _sourceimage Is Nothing Then
                SetError(-1, "The source image is not set.")
                Return
            End If
            If Not _resizedimage Is Nothing Then
                _resizedimage.Dispose()
                _resizedimage = Nothing
            End If
     
            Dim xscale As Single = _sourceimage.Width / width
            Dim yscale As Single = _sourceimage.Height / height
            Dim scale As Single = IIf(xscale > yscale, xscale, yscale)
            If scale < 1.0 Then scale = 1.0
     
            width = CInt(_sourceimage.Width / scale)
            height = CInt(_sourceimage.Height / scale)
     
            Select Case mode
                Case 0
                    Try
                        _resizedimage = New Bitmap(width, height)
                        Dim g As Graphics = _
                            Graphics.FromImage(_resizedimage)
                        g.DrawImage(_sourceimage, 0, 0, _
                            _resizedimage.Width + 1, _
                            _resizedimage.Height + 1)
                    Catch e As Exception
                        SetError(-1, e.Message)
                    End Try
     
                Case 1
                    Try
                        _resizedimage = _sourceimage.GetThumbnailImage( _
                            width, height, Nothing, IntPtr.Zero)
                    Catch e As Exception
                        SetError(-1, e.Message)
                    End Try
            End Select
        End Sub
    End Class
     
     
     

    User rating: 0/10 (0 votes)
    Rate this code sample:
    • ~
    3414 bytes  
    Created: 2004-07-27 10:28:48  
    Modified: 2007-03-06 18:57:59  
    Visits in 7 days: 123  
    Listed functions:
    ShellExecute
    Printer friendly API declarations
    My comment:
    .Net code: GetThumbnailImage works well when the requested thumbnail image has a size of about 120 x 120.
    Word Index links for this example:
    Translate this page:
      Spanish    Portuguese    German    French    Italian  
    FreeTranslation.com offers instant, free translations of text or web pages.
    User Contributed Notes:
    There are no notes on this subject.


    Copyright © 2001-2013 News2News, Inc. Before reproducing or distributing any data from this site please ask for an approval from its owner. Unless otherwise specified, this page is for your personal and non-commercial use. The information on this page is presented AS IS, meaning that you may use it at your own risk. Microsoft Visual FoxPro and Windows are trade marks of Microsoft Corp. All other trademarks are the property of their respective owners. 

    Privacy policy
    Credits: PHP (4.4.9), an HTML-embedded scripting language, MySQL (5.1.55-log), the Open Source standard SQL database, AceHTML Freeware Version 4, freeware HTML Editor of choice.   Hosted by Korax Online Inc.
    Last Topics Visited (54.234.67.55)
    3 sec.Function: 'SHGetFileInfo'
    6 sec.Function: 'LoadLibraryEx'
    Function group: 'Dynamic-Link Library'
    39.72 min.Function: 'GdipGetImageGraphicsContext'
    Function group: 'GDI+ Image'
    11.39 hrs.Example: 'Storing screen shot of a form to bitmap file'
     Example: 'Winsock: reading email messages (POP3, port 110)'
    11.65 hrs.Example: 'Reading and setting system access privileges for the current process'
    20.54 hrs.Example: 'How to ping a remote site using IP Helper API calls'
    2 day(s)Example: 'Configuring DEVMODE structure for a printer'
     Function: 'GetKeyboardLayout'
    Function group: 'Keyboard Input'
     Function: 'GetBkMode'
    Google
    Advertise here!