Quantcast
Channel: CodeGuru Forums - Visual C++ Programming
Viewing all articles
Browse latest Browse all 3042

memcpy error in MFC

$
0
0
Hi,

I load an image(768*256) using a file path(OpenImageFilePath).

After load an image, I start to read the loaded Image data using GetBits method and plot the same image data(768*256).

I'm using the memcpy method, for that i'm getting the below error. memmove function also giving the same error message.

Please clear me.

File Name : memcopy.asm
rep movsd ;N - move all of our dwords


Code for your reference
Code:

void CDlg :: FileOpen()
{
        CFileException CFileEx;
        CStdioFile ReadFile;

        // szFilters is a text string that includes two file name filters:
        TCHAR szFilters[]= _T("Image Files (*.bmp)");

        CFileDialog fileDlg(TRUE, _T("bmp"), _T("*.bmp"),

        OFN_FILEMUSTEXIST | OFN_HIDEREADONLY, szFilters);

        fileDlg.m_ofn.lpstrTitle = _T("Offline Images");

        fileDlg.m_pOFN->lpstrInitialDir=_T("C:\\AcceptedImg\\");

        if(fileDlg.DoModal() == IDOK)
        {
                OpenImageFilePath = fileDlg.GetPathName();
                OpenImageFileFlag = true;
        }

        //Refresh Window
        CRect mRect;
        GetClientRect(&mRect);
        InvalidateRect(&mRect);
}

void CDlg::OnPaint()
{
        CPaintDC dc(this); // device context for painting
        if(OpenImageFileFlag)
        {        //Load Image
                CDC *pDC;
                pDC=GetDC();

                CImage ObjImage ;
                ObjImage.Load(OpenImageFilePath) ; //Image Path

                CBitmap pBitmap ;
                pBitmap.Attach(ObjImage.Detach());

                BITMAP bm;
                pBitmap.GetObject( sizeof(BITMAP), &bm );       

                CDC dcMem;
                dcMem.CreateCompatibleDC( pDC );

                CBitmap* pbmpOld = dcMem.SelectObject( &pBitmap );
                pDC->BitBlt(25,360, bm.bmWidth, bm.bmHeight,&dcMem, 0,0, SRCCOPY );

                dcMem.SelectObject( pbmpOld );
                ReleaseDC( pDC );

                //Get Bits from that image
                CImage atlImage;
                atlImage.Load(OpenImageFilePath);

                void* pPixel = NULL;
                pPixel  = atlImage.GetBits();

                int pitch = atlImage.GetPitch();
                int bytes = abs(pitch) * atlImage.GetHeight();

                const BYTE * src = NULL;
                src = (BYTE*)atlImage.GetBits();

                if(pitch < 0) src -= bytes;

                BYTE * pBitmapData = NULL;
                pBitmapData = new BYTE[bytes];

                memcpy(pBitmapData, src, bytes);
                //memmove(pBitmapData, src, bytes); //Getting Error foe use memmove func also

                width = atlImage.GetWidth();       
                height = atlImage.GetHeight();
               
                for (int y = 0; y < width; y = y + 1)
                {
                        iIndex = y + (width * height) - width;
                        for (int x = 0; x < height ; x = x + 1)
                        {
                                OfflineImageData[iIndex] = (byte)(*(pBitmapData + iIndex));
                                OfflineData[y][x] = OfflineImageData[iIndex];
                                iIndex = iIndex - width;
                        }
                }
        }//End OpenImageFileFlag
        for (int y = 0; y < width; y = y + 1)//1024 ImageHeight
        {
                for (int x = 0; x < height-1 ; x = x + 1)//256 ImageWidth
                {
                        SetPixelV(dc,25+y,50+x,RGB(OfflineData[y][x],OfflineData[y][x],OfflineData[y][x]));
                }
        }
}


Viewing all articles
Browse latest Browse all 3042

Trending Articles