HowTo: DDS images in VB6

ZabMilenko

Warlord
Joined
Apr 22, 2004
Messages
106
Location
Medford, Oregon
NOTE: I know this is not a utility program, but those who make utility programs will find this handy. It took me several hours to figure out the DDS file format before I realized I was doing it all wrong. This is a little tutorial for VB developers who want to be able to display DDS images in their app. It should be simple to adapt for VB.NET.

PRINT THIS OUT AND USE IT AS A CHECKLIST

1) Open up the project that you want to display DDS images in OR create a new project.

2) Download This File: http://prdownloads.sourceforge.net/freeimage/FreeImage380Win32.zip?download to a temp folder (outside of your project directory).

3) Open up the zip file and copy ONLY the following 4 files to your project directory:

$archive$\FreeImage\Dist\*.* (3 files)
$archive$\FreeImage\Wrapper\VB6\mfreeimage\MFreeImage.bas (1 file)

The rest of the archive can be discarded.

4) Add the mFreeImage.bas file to your project.

5) Add this sub to a form or module. You shouldnt edit the mFreeImage.bas file, but that is your choice:

Code:
Public Sub DrawImageOnPictureBox(ByVal vFileName As String, ByVal vImageType As FREE_IMAGE_FORMAT, vPictureBox As PictureBox)

    Dim mDib As Long
    
    mDib = FreeImage_Load(vImageType, vFileName)

    ' OLE_PICTURE is the StdPicture object, which can be drawn almost anywhere!
    vPictureBox.Picture = FreeImage_GetOlePicture(mDib)


    FreeImage_Unload mDib
    
End Sub

6) And of course, to display a DDS file in Picture1:

Code:
DrawImageOnPictureBox PathToDDS$, FIF_DDS, Picture1



I hope this helps out other devs. It's certainly made my project a little nicer. :-)
 
Now thats cool, I was going to make a request for this very thing or a link to one today and you've replied a day before :)
 
Back
Top Bottom