Results 1 to 3 of 3

Thread: VB6 - BmpGen Helper Class for WIA 2.0

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    VB6 - BmpGen Helper Class for WIA 2.0

    Problem

    While WIA 2.0 provides a lot of handy image capture and manipulation tools for VB, VBA, and VBScript one thing it isn't good at is creating a blank image.

    There is a standard way to do this and it is even described in the code samples within the WIA 2.0 documentation. The bad news is that for anything but tiny images this can be impractically slow because of the way the WIA.Vector's .Add() method works for creating ARGB bitmaps.


    Solution

    You can load an image into a WIA.ImageFile object from a disk file in any of several image file formats. This works well for some applications, especially if you need a fairly complex background image to stamp other things onto. The downsides are that (a.) you need to carry along this extra image file with your program, and (b.) it doesn't address cases where you need to deal with images of sizes unknown until runtime.

    However you do have the option of loading an image file "image" from a Byte array into a WIA.Vector through its .BinaryData property, and from there you can create an ImageFile object or a StdPicture object. This means you could store such a serialized "image file" as a resource and use it, or you might build one on the fly.

    This is what the BmpGen object does with its single .MakeMono() method: create and return a monochrome BMP file image as a Byte array, with the dimensions and background color you specify. This addresses the dynamic dimensions issue.


    Demo

    The BmpGen class is packaged along with a demo Project in the attached archive.

    The purpose of the demo is to show how you might make use of BmpGen.MakeMono() along with WIA to create "blank" solid color backdrop images to manipulate further. It also helps compare the performance of this technique with the standard wa of making a blank image with WIA, which gets much slower as the image dimensions increase.

    Each of the three test cases creates a background and then stamps two transparent GIF "screen beans" characters onto it and displays the result in a VB6 Image control.

    Name:  sshot.png
Views: 3690
Size:  14.7 KB

    The "fancy" test case loads an included PNG file from disk as the background. This works well enough and might be better for cases where you don't want a simple solid color backdrop, but has the limitations already described above.

    The timings cover just the creation of the backdrop image prior to the stamping steps. They're rough timings based on Timer() but this should be accurate enough to illustrate the difference in performance.


    Requirements

    BmpGen has no dependencies that aren't included in Windows 95 or later. The demo itself requires WIA 2.0 which is part of Windows Vista and subsequent versions of Windows, and can also be installed into Windows XP SP1 or later if you grabbed the download before Microsoft removed it in preparation for XP's impending retirement.

    To use the demo as-is you need VB6, but you could also do the same kind of thing in VBA applications making use of BmpGen which has no VB6-specific features in it.

    VBScript is not supported, but you could create an VB6 ActiveX DLL containing BmpGen and make use of that in VBScript.
    Attached Files Attached Files

  2. #2

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: VB6 - BmpGen Helper Class for WIA 2.0

    To see the difference in performance even better you could double the 320x240 images to 640x480.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: VB6 - BmpGen Helper Class for WIA 2.0

    For the curious I created an Excel Workbook that uses BmpGen.
    Attached Files Attached Files

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width