Storing Bitmaps into an Array

Environment: VC6, NT4

Introduction

The CArrayBITMAP class stores a Windows bitmap and provides member functions to manipulate the bitmap's array.

Bitmaps are stored in an array with elements such as a BITMAP structure. This class is recommended for temporary image storage. Bitmaps may be any standard type and size. The quantity of kept images is limited to the system's memory size and maximal size of type integer.

This class has the following public functions for its use:

//add new bitmap from object CBitmap, return Bitmap Index in array
int Add(CBitmap * pCBitmap);
//add new bitmap from pointer
int
Add(LPBITMAP pBITMAP);
//get bitmap's count in array
int GetSize();
//replace bitmap by index
BOOL Replace(int iIndex, LPBITMAP pBITMAP);
//remove bitmap from array by index
BOOL Remove(int iIndex);
//remove all bitmaps from array
void RemoveAll();
//return pointer to bitmap in array (get bitmap)
LPBITMAP GetAt(int iIndex);

Example of This Class's Use

CArrayBITMAP arrayBitmaps;
CBitmap m_bitmap;

     m_bitmap.LoadBitmap(OBM_MYBIT);     //load from resources
int
  iIndex = arrayBitmaps.Add(&bit);       //add bitmap to array

...

CBitmap bitStored;
LPBITMAP pBmp = arrayBitmaps.GetAt(iIndex);
//get bitmap from array
    if(pBmp != NULL)
      bitStored.CreateBitmapIndirect(pBmp);
...

Downloads

Download source - 3.32 Kb


Comments

  • how can get image of hidden window

    Posted by jags_ddit on 03/03/2005 12:30am

    firstly, I thanks to him which had put this artical.This artical had provide me very interesting needed help. now I want to grab the hiden window by Knowing it HWND parameter but i can grab it completely can any one can give me some guide so that i can do it?

    Reply
  • Can you show me how to compress a BMP?

    Posted by nguyenquang on 04/04/2004 09:31am

    Your code is good! Now I know how to store BMP into an array. Do you know how to compress a BMP using Facsimile compression algorithm? Please contact me at:ngnguyenquang@yahoo.com

    Reply
  • what is bit?

    Posted by Legacy on 11/13/2003 12:00am

    Originally posted by: Gauri

    HI Alex,
    
    

    I was looking at this example:
    Where is bit defined because it is used in this line
    int iIndex = arrayBitmaps.Add(&bit); //add bitmap to array


    Also I would like to know whether we can use standard function like StretchBlt or BitBlt to display the iamges stored in the array using this example. Can you give a short example.

    And is there any way to display multiple bitmaps simultaneously . My project requires that the bitmap images selected by the user from a folder should be dispalyed at the same time in a grid like structure.

    Reply
  • Other option - standard way of saving into bitmap array

    Posted by Legacy on 11/07/2003 12:00am

    Originally posted by: Arie

    Why not using a standar way of saving an image into a list, array which has all the neded functionality
    Here is a small example that ilustrate ny idea :
    NOTE : all the IDB_... are a resource IDS that can be cahged to read from file into a CBitmap structure.

    CImageList* m_pimagelist ;

    void CMyClass::SetBitmapsArray()
    {
    CBitmap bitmap;

    m_pimagelist = new CImageList();
    m_pimagelist->Create(18, 16, ILC_MASK, 4, 2);

    bitmap.LoadBitmap(IDB_ITEM_ROOT_NOT_SELECTED);
    m_pimagelist->Add(&bitmap, (COLORREF)0xFFFFFF);
    // the delete needed because U already attached this bitmap)
    bitmap.DeleteObject();
    bitmap.LoadBitmap(IDB_ITEM_ROOT_SELECTED);
    m_pimagelist->Add(&bitmap, (COLORREF)0xFFFFFF);
    bitmap.DeleteObject();
    bitmap.LoadBitmap(IDB_ITEM_SUB_ROOT_NOT_SELECTED);
    m_pimagelist->Add(&bitmap, (COLORREF)0xFFFFFF);
    bitmap.DeleteObject();
    bitmap.LoadBitmap(IDB_ITEM_SUB_ROOT_SELECTED);
    m_pimagelist->Add(&bitmap, (COLORREF)0xFFFFFF);
    bitmap.DeleteObject();
    bitmap.LoadBitmap(IDB_ITEM_NOT_SELECTED);
    m_pimagelist->Add(&bitmap, (COLORREF)0xFFFFFF);
    bitmap.DeleteObject();
    bitmap.LoadBitmap(IDB_ITEM_SELECTED);
    m_pimagelist->Add(&bitmap, (COLORREF)0xFFFFFF);
    bitmap.DeleteObject();
    bitmap.LoadBitmap(IDB_ITEM_NOT_SELECTED_PATTERN);
    m_pimagelist->Add(&bitmap, (COLORREF)0xFFFFFF);
    bitmap.DeleteObject();
    bitmap.LoadBitmap(IDB_ITEM_SELECTED_PATTERN);
    m_pimagelist->Add(&bitmap, (COLORREF)0xFFFFFF);
    bitmap.DeleteObject();
    }

    Use standard is an easy way some time.

    I hope that this will help

    Reply
  • resize bitmap file

    Posted by Legacy on 05/13/2003 12:00am

    Originally posted by: michelle

    can anyone tell me how to resize the bitmap file . i load bitmap file which is 632*324(too big) and wanna to resize it to 92 *112...... i do not know how to do it ...plz help thank

    • ->

      Posted by shekhar_dawer on 01/29/2005 02:09am

      Hello if u know how to resize a bitmap now then pz tell me also thanx

      Reply
    • :(

      Posted by jabby12 on 07/24/2004 11:35pm

      I want to know too!

      Reply
    Reply
  • hi..alex

    Posted by Legacy on 11/24/2002 12:00am

    Originally posted by: maziah

    alex...
    i'm try to run Carraybitmap in visual C++ but it have some errors as below :
    Compiling...
    Skipping... (no relevant changes detected)
    ArrayBITMAP.cpp
    Linking...
    nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __endthreadex
    nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __beginthreadex
    libcd.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
    Debug/ArrayBITMAP.exe : fatal error LNK1120: 3 unresolved externals
    Error executing link.exe.

    ArrayBITMAP.exe - 4 error(s), 0 warning(s)

    perphaps, you will help me to make sure it works succesfully.best regard and thank u

    Reply
  • how to change bitmap size

    Posted by Legacy on 11/21/2002 12:00am

    Originally posted by: maziah

    hi alex...
    
    i have a problem how to change bitmap size( example from 512x256 image to 128x128) and then convert bmp image to array in c code.would you help me, alex... i need that source code as soon as possible..thanks alex.

    • oh yes

      Posted by jabby12 on 07/24/2004 11:37pm

      If you have to source code,please give me one ,thanks,alex! my email:jabby12@163.com

      Reply
    Reply
  • What's the difference to vector<CBitmap> ??

    Posted by Legacy on 11/05/2002 12:00am

    Originally posted by: efi

    Maybe it's just that I'm missing something here - anyhow - I was wondering what's the big point compared to the vector<CBitmap> solution?

    Greetings

    Reply
  • not so bad??

    Posted by Legacy on 10/29/2002 12:00am

    Originally posted by: Johnthan

    CImageList is also a good choice?

    Reply
  • How to build a DIB from raw data

    Posted by Legacy on 10/27/2002 12:00am

    Originally posted by: jeff


    Here I need some help.

    In photoshop,we can store a image into raw format.In this

    format, all the data in the file is the image data itself.

    That is if a image is 8-bit with the size of 512*512,then

    the size of the file is 512*512 byte.

    My question is that how can I develope a program to read

    the raw format file and create a CDIB class? The problem is

    how to fill the image data into the class? I think there

    must to do some convertions.For example,in DIB,the width

    of a line should be divided by 4.

    Can any expert help me?

    Thanks a lot.

    Reply
  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: November 20, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Are you wanting to target two or more platforms such as iOS, Android, and/or Windows? You are not alone. 90% of enterprises today are targeting two or more platforms. Attend this eSeminar to discover how mobile app developers can rely on one IDE to create applications across platforms and approaches (web, native, and/or hybrid), saving time, money, and effort and introducing apps to market faster. You'll learn the trade-offs for gaining long …

  • IBM Worklight is a mobile application development platform that lets you extend your business to mobile devices. It is designed to provide an open, comprehensive platform to build, run and manage HTML5, hybrid and native mobile apps.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds