Quantcast
Channel: VBForums - CodeBank - Visual Basic 6 and earlier
Viewing all articles
Browse latest Browse all 1529

[VB6] MapStitcher.cls - Create imagemaps from images

$
0
0
Sometimes it can be handy to make use of the PictureClip control or similar approaches to grab and use small images "cut out" from a larger image set up in a grid layout. But usually we have separate images to work with, and stitching them together into a larger "imagemap" image can be tedious.

MapStitcher.cls is a VB6 class that makes use of WIA 2.0 to create such "maps." A really simple thing but you might find it useful.


Limitations

Since WIA 2.0 only offers limited capabilities for handling transparency, this works best when you have images that make use of mask color transparency. If you give it source images with PNG or GIF transparency it can "stamp" these onto a backdrop making use of the transparency but there isn't any way to retrieve a composite image with any transparency itself.

This isn't all bad, since so many VB6 controls and operations make use of mask color transparency anyway. But note that to be effective your source images should use the same mask color, and you'd want to set the composite image's backdrop color to match that.


Demo

I've attached the class in a demo Project "StitchMap."

StitchMap loads the images that it finds in the directory "Samples" and assumes a magenta mask/backdrop color (255, 0, 255). It looks at the first loaded image and places its dimensions in pixels into the Cell width and Cell Height TextBoxes, and puts a 4 into the Cells per row TextBox. You can change those values.

When you click the Stitch button it passes these values to MapStitcher, which creates a stitched image. The demo displays this:


Name:  sshot1.png
Views: 76
Size:  14.0 KB

Oops! One image got cut off.


Name:  sshot2.png
Views: 70
Size:  14.5 KB

Changed dimensions to match the large image


Then you could click the Save as BMP button and it will save this to Stitched.bmp and reset.

It also works with a longer list of input images, though this will run a little longer:

Name:  sshot3.png
Views: 68
Size:  45.1 KB


Summary

Sometimes you need to create imagemaps from small images, but positioning them using Paint, etc. can be a pain.

MapStitcher shows a way to do this more easily. You could wrap this in a program with more options: browse to the input folder, list the input files and their dimensions, a backdrop color-picker, save-as dialog, etc.

You could also modify MapStitcher, replacing WIA 2.0 by GDI+ flat API calls to obtain more options such as saving the composite image as a PNG with a transparent backdrop.
Attached Images
   
Attached Files

Viewing all articles
Browse latest Browse all 1529

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>