Page 1 of 1

Blend 2 pictures

Posted: Mon Mar 20, 2006 1:53 am
by emarti
I wanna share with you.....

Code: Select all

// Blend 2 pictures
wxImage::AddHandler( new wxBMPHandler);
wxImage i1,i2;
i1.LoadFile(_T("1.bmp"), wxBITMAP_TYPE_BMP);
i2.LoadFile(_T("2.bmp"), wxBITMAP_TYPE_BMP);
		
unsigned char r1,r2,r,g1,g2,g,b1,b2,b;
int x,y; // i1 image's width & height
for (int x=0; x<i1.GetWidth();x++)
	{
     for (int y=0; y<i1.GetHeight(); y++){
            // i1 and i2 RGB values
            r1 = i1.GetRed(x,y);
            r2 = i2.GetRed(x,y);
            g1 = i1.GetGreen(x,y);
            g2 = i2.GetGreen(x,y);
            b1 = i1.GetBlue(x,y);
            b2 = i2.GetBlue(x,y);
            // New RGB
            r = (r1 + r2)/2;
            g = (g1 + g2)/2;
            b = (b1 + b2)/2;
            g = g << 8;
            b = b << 16;
            // SetRGB
            i2.SetRGB(x,y,r,g,b);       
      }
     }
WxStaticBitmap1->SetBitmap(wxBitmap(i2));
Respectly,
emarti

Posted: Tue Mar 21, 2006 11:58 pm
by emarti
Hi, again. A little sample.
Image

Download sample (with source)
http://emarti.50webs.com/Blend2Pic.zip

Suggestion

Posted: Wed Mar 22, 2006 11:03 am
by priyank_bolia
Manipulate the image buffer, rather than calling the functions to access the pixels each time.

Posted: Wed Mar 22, 2006 10:30 pm
by emarti
Hi,
How to manipulate the image buffer? I am poor about this concept probably.

Respectly,
emarti

Posted: Thu Mar 23, 2006 12:47 am
by timg
look at wxImage.GetData(), it returns a pointer to the raw data.