Click here to Skip to main content
15,918,193 members
Home / Discussions / Graphics
   

Graphics

 
GeneralRe: PictureBox using too much memory Pin
Luc Pattyn5-Jan-08 11:47
sitebuilderLuc Pattyn5-Jan-08 11:47 
GeneralRe: PictureBox using too much memory Pin
gembob9-Jan-08 3:40
gembob9-Jan-08 3:40 
GeneralRe: PictureBox using too much memory Pin
Luc Pattyn9-Jan-08 4:22
sitebuilderLuc Pattyn9-Jan-08 4:22 
GeneralRe: PictureBox using too much memory Pin
gembob1-Feb-08 7:22
gembob1-Feb-08 7:22 
GeneralRe: PictureBox using too much memory Pin
Luc Pattyn1-Feb-08 10:12
sitebuilderLuc Pattyn1-Feb-08 10:12 
GeneralRe: PictureBox using too much memory Pin
gembob4-Feb-08 3:38
gembob4-Feb-08 3:38 
GeneralRe: PictureBox using too much memory Pin
Luc Pattyn4-Feb-08 4:54
sitebuilderLuc Pattyn4-Feb-08 4:54 
GeneralHelp Required : Creating DIBSection from raw image data ( Searched all possible forums, could not find answer ) Pin
Sharath Jagannath3-Jan-08 20:49
Sharath Jagannath3-Jan-08 20:49 
Below is the code snippet i use to create the gray scale image (8bpp) from scratch using CreateDIBSection and displays it onto the screen.

Image that is displayed has most of it data grey in color and the image data seems to be merged with lot of noise... I doubt the issue is with the image creation....

need some help on this, all help appreciated
Let me know the flaws in the code, I am new to Windows graphic programming.

btw, i work with MFC Smile | :)
Code :


struct ImageData
{
int rows;
int cols;
int bpp;
.
.
.
.
.
.
}; // Other fields are not relevant for Image Display

int pixmap[256]; // Palette to be used

ImageData curimage; // Member Variable in the App Dialog Class


void CExampleDlg::SetBitmapInfo (LPBITMAPINFO DIB_info, ImageData *imageptr)
{
DIB_info->bmiHeader.biSize = 40;
DIB_info->bmiHeader.biPlanes = 1;
DIB_info->bmiHeader.biBitCount = imageptr->bpp; // only 8 (handling only 8bpp images)
DIB_info->bmiHeader.biWidth = imageptr->cols;
DIB_info->bmiHeader.biHeight = imageptr->rows;
DIB_info->bmiHeader.biCompression = BI_RGB;
DIB_info->bmiHeader.biSizeImage = imageptr->rows * imageptr->cols;
DIB_info->bmiHeader.biXPelsPerMeter = 0;//0xb12; //(72ppi)
DIB_info->bmiHeader.biYPelsPerMeter = 0;//0xb12;
DIB_info->bmiHeader.biClrUsed = 256;
DIB_info->bmiHeader.biClrImportant = 256;


DIB_info->bmiColors[0].rgbBlue = 0;
DIB_info->bmiColors[0].rgbGreen = 0;
DIB_info->bmiColors[0].rgbRed = 0;
DIB_info->bmiColors[0].rgbReserved = 0;

}

void CExampleDlg::GetDIBmp (unsigned char *bmp,
CBitmap *pimage,
ImageData *imageptr,
int height,
int width)
{
BITMAPINFO DIB_info;
HBITMAP hBitmap = NULL;
HDC hMemDC = NULL;
HGDIOBJ hOldObj = NULL;


// Set the BitmapInfo
SetBitmapInfo (&DIB_info, imageptr);

DIB_info.bmiHeader.biHeight = height;
DIB_info.bmiHeader.biWidth = width;

hMemDC = ::CreateCompatibleDC(NULL);

// create device independent bitmap section
hBitmap = ::CreateDIBSection(hMemDC,
&DIB_info,
DIB_RGB_COLORS,
NULL,
NULL,
SRCCOPY);

if ( !hBitmap )
{
exit (-1);
}

DIB_info.bmiHeader.biHeight = imageptr->rows;
DIB_info.bmiHeader.biWidth = imageptr->cols;

//CreateDIBTable (DIB_info,hMemDC,bmp);
hOldObj = ::SelectObject(hMemDC, hBitmap);


StretchDIBits(hMemDC, 0, 0,
width, height, 0, 0,
DIB_info.bmiHeader.biWidth,
DIB_info.bmiHeader.biHeight,
bmp,&DIB_info,
DIB_RGB_COLORS,
SRCCOPY);


// restore DC object
::SelectObject(hMemDC, hOldObj);

// clean up
::DeleteObject(hMemDC);

pimage->Attach(hBitmap);

}

void CExampleDlg::GetPalette (BITMAPINFO DIB_info,
CBitmap *bitmap,
CPalette *pal)
{
unsigned long nColors = DIB_info.bmiHeader.biClrUsed;

// Create a halftone palette if colors > 256.
CClientDC dc(NULL); // Desktop DC
if( nColors > 256 )
pal->CreateHalftonePalette( &dc );
else
{
// Create the palette

RGBQUAD *pRGB = new RGBQUAD[nColors];
CDC memDC;
memDC.CreateCompatibleDC(&dc);

memDC.SelectObject( bitmap );
::GetDIBColorTable( memDC, 0, nColors, pRGB );

UINT nSize = sizeof(LOGPALETTE) + (sizeof(PALETTEENTRY) * nColors);
LOGPALETTE *pLP = (LOGPALETTE *) new BYTE[nSize];

pLP->palVersion = 0x300;
pLP->palNumEntries = nColors;

for( int i=0; i < nColors; i++)
{
pLP->palPalEntry[i].peRed = pixmap[i];
pLP->palPalEntry[i].peGreen = pixmap[i];
pLP->palPalEntry[i].peBlue = pixmap[i];
pLP->palPalEntry[i].peFlags = 0;
}

pal->CreatePalette( pLP );

delete[] pLP;
delete[] pRGB;
}

}

void CExampleDlg::CreateDIBTable (BITMAPINFO DIB_info,HDC hMemDC,
unsigned char *bmp)
{
if (DIB_info.bmiHeader.biBitCount <= 8)
{
HPALETTE hPalette =
(HPALETTE) GetCurrentObject(hMemDC, OBJ_PAL);
if (hPalette)
{
PALETTEENTRY pPaletteEntries[0x100];
UINT nEntries = GetPaletteEntries(hPalette,
0, DIB_info.bmiHeader.biClrUsed,
pPaletteEntries);
if (nEntries)
{
ASSERT(nEntries <= 0x100);
for (UINT nIndex = 0; nIndex < nEntries; nIndex++)
{
pPaletteEntries[nIndex].peRed = pixmap [nIndex];
pPaletteEntries[nIndex].peGreen = pixmap [nIndex];
pPaletteEntries[nIndex].peBlue = pixmap [nIndex];
pPaletteEntries[nIndex].peFlags = 0;
}
int entries = SetDIBColorTable(hMemDC, 0,
0x100, (RGBQUAD*) pPaletteEntries);
VERIFY(entries == nEntries);
}
}
}
}

void CExampleDlg::ShowImage()
{

unsigned char *bmp;
CGdiObject *oldDC;
BITMAPINFO dib;

bmp = ViewImage(&curimage);

CBitmap *pimage = new CBitmap;
GetDIBmp (bmp,pimage,&curimage,
100 /* Height */,
100 /* Width */);


// Identifies the device context(dialog) of client area
CPaintDC dc(this);
CDC pMemDC;

pMemDC.CreateCompatibleDC ( &dc );
oldDC = pMemDC.SelectObject ( pimage );

CPalette pal;
this->GetPalette (dib,pimage,&pal);

if((dc.GetDeviceCaps(RASTERCAPS) & RC_PALETTE) && pal.m_hObject != NULL )
{
dc.SelectPalette( &pal, FALSE );
int entry = dc.RealizePalette();
}


dc.StretchBlt (30,30,
100,
100,
&pMemDC,
0,
0,
curimage.cols,
curimage.rows,
SRCCOPY);



::SelectObject (pMemDC.m_hDC,oldDC);
DeleteObject (pMemDC.m_hDC);

delete []bmp;
delete pimage;

}
GeneralRe: Help Required : Creating DIBSection from raw image data ( Searched all possible forums, could not find answer ) Pin
Mark Salsbery4-Jan-08 8:00
Mark Salsbery4-Jan-08 8:00 
GeneralRe: Help Required : Creating DIBSection from raw image data ( Searched all possible forums, could not find answer ) Pin
Sharath Jagannath6-Jan-08 19:15
Sharath Jagannath6-Jan-08 19:15 
Questionopengl 1.2 Pin
Dr Willy2-Jan-08 22:25
Dr Willy2-Jan-08 22:25 
GeneralRe: opengl 1.2 Pin
Tim Craig2-Jan-08 23:22
Tim Craig2-Jan-08 23:22 
GeneralRe: opengl 1.2 Pin
Dr Willy4-Jan-08 9:07
Dr Willy4-Jan-08 9:07 
QuestionWhat causes the DirectShow EC_COMPLETE event to be set Pin
Yair Han31-Dec-07 7:33
Yair Han31-Dec-07 7:33 
GeneralRe: What causes the DirectShow EC_COMPLETE event to be set Pin
tanvon malik2-Jan-08 4:05
tanvon malik2-Jan-08 4:05 
QuestionHow to Load .X File using DirectX9? Pin
snehat28-Dec-07 18:28
snehat28-Dec-07 18:28 
AnswerRe: How to Load .X File using DirectX9? Pin
MarkB7773-Jan-08 12:19
MarkB7773-Jan-08 12:19 
Generalcharacter segmentation Pin
zhaojun27-Dec-07 18:04
zhaojun27-Dec-07 18:04 
General.max to .x conversion Pin
DanB198324-Dec-07 3:37
DanB198324-Dec-07 3:37 
GeneralRe: .max to .x conversion Pin
Paul Conrad24-Dec-07 11:32
professionalPaul Conrad24-Dec-07 11:32 
GeneralRe: .max to .x conversion Pin
DanB198324-Dec-07 21:42
DanB198324-Dec-07 21:42 
GeneralRe: .max to .x conversion Pin
El Corazon24-Dec-07 11:53
El Corazon24-Dec-07 11:53 
GeneralRe: .max to .x conversion Pin
DanB198324-Dec-07 21:43
DanB198324-Dec-07 21:43 
QuestionZooming an image in a PictureBox Pin
gp005@hotpop.com29-Nov-07 6:46
gp005@hotpop.com29-Nov-07 6:46 
AnswerRe: Zooming an image in a PictureBox Pin
Luc Pattyn29-Nov-07 8:02
sitebuilderLuc Pattyn29-Nov-07 8:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.