Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / desktop / Win32

Irregular or non rectangular shaped bitmap

2.00/5 (8 votes)
4 Feb 2008CPOL2 min read 4   467  
Convert rectangular bitmap into non rectangular bitmap (.ppg)
Image 1

Introduction

So many times we feel need of non rectangular bitmap, bitmap which store only the required

portion of the picture leaving outside area. You just do it by defining the desired area and call

a function to store the picture inside the selected area. Then just by calling another function

to make a bitmap of stored pixels and use it anywhere. The pixels outside the selected area

in bitmap will not be visible in bitmap because it uses alpha value 0.

Detail

This application provides the capability to user to transform rectangular bitmap or picture to non
rectangular picture by clipping areas outside the boundaries. User can separate out the desired part and undesirable part of picture just by drawing polygon using mouse cursor.

Background

Whenever we store some image on secondary device we store the image in outbound rectangular area. In that case rectangular area which is not part of image has to be filled with some color and consumes unwanted memory. Instead if only the desired area of image is stored then it gives a lot of advantage in saving secondary memory. Loading and saving image will be more cpu intensive compared to rectangular bitmap but more space effective.

Points of Interest

This algorithm stores only the pixels color inside the polygon boundary and saves a lot of extra
space that was wasted by outside area. For example take case of a "cross" picture actually need only 10% part of total storage and wastes 90% of storage. So our algorithm will save 90% of space in this case.

How to use

Steps to perform.

1. Open normal bitmap.

2. Define outbound area polygon by free polygon/ bounded polygon.

3. Save irregular shaped bitmap as ppg picture.

4. Close current picture.

5. Open last saved ppg picture.

6. If more do steps 2 to 5.

7. Look at the size of original bitmap and ppg picture. Ya It does....

History

I would like to listen users review/comments on this article. It stores picture pixels in ARGB format, if further compression like jpeg or gif is provided it may prove better than them also.

Thanks

Vikas Maan, Tek

vikas.jpg

License

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