Click here to Skip to main content
16,006,564 members
Home / Discussions / Graphics
   

Graphics

 
QuestionDirect3DCreate9 question Pin
Pedram Behroozi15-Nov-08 8:38
Pedram Behroozi15-Nov-08 8:38 
AnswerRe: Direct3DCreate9 question Pin
Baltoro16-Nov-08 10:40
Baltoro16-Nov-08 10:40 
GeneralRe: Direct3DCreate9 question Pin
Pedram Behroozi16-Nov-08 11:22
Pedram Behroozi16-Nov-08 11:22 
GeneralRe: Direct3DCreate9 question Pin
Baltoro20-Nov-08 14:01
Baltoro20-Nov-08 14:01 
GeneralRe: Direct3DCreate9 question Pin
Pedram Behroozi20-Nov-08 22:02
Pedram Behroozi20-Nov-08 22:02 
GeneralRe: Direct3DCreate9 question Pin
Mark Churchill13-Jan-09 18:51
Mark Churchill13-Jan-09 18:51 
QuestionExport to Bitmap. Pin
vinay_K10-Nov-08 1:54
vinay_K10-Nov-08 1:54 
Question[please help]why i cannot render my pic?thks! Pin
kaviniswell7-Nov-08 16:19
kaviniswell7-Nov-08 16:19 
i wana to load a JPG file and render it on gui,but no any result however...and every time it prints: Render PIC SUC!! and i cannot resolve the problem,my code is:

// open the pic file 
void CTestLoadJPEGDlg::OnBtnNew() 
{
    CFileDialog cFileDlg( TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, "File(*.JPEG;*.JPG;*.BMP)|*.JPEG;*.JPG;*.BMP||", NULL);
      
    if (IDOK == cFileDlg.DoModal())
    {
        // Get the pic and length
        CString strPicFilePath;
        strPicFilePath = cFileDlg.GetPathName();
        TRACE("the file path:%s\n",strPicFilePath);
        CFile cFile(strPicFilePath,CFile::modeRead);
        int nPicFileBufSize = cFile.GetLength(); 

        // Allocates movable memory. 
        // In Win32, memory blocks are never moved in physical memory, but they can be moved within the default heap. 
        HGLOBAL hGlobal = ::GlobalAlloc(GMEM_MOVEABLE, nPicFileBufSize);
        if(NULL != hGlobal)
        {
            // locks a global memory object and returns a pointer to the first byte of the object's memory block
            LPVOID lpData = NULL;
            lpData = ::GlobalLock(hGlobal);
            if (NULL != lpData)
            {
                // read and lock
                cFile.ReadHuge(lpData, nPicFileBufSize);
                GlobalUnlock(hGlobal);

                // create a stream object in the heap
                IStream *pIstream = NULL;
                CreateStreamOnHGlobal(hGlobal,TRUE,&pIstream);
                if (NULL != pIstream)
                {
                    // load the pic by the stream object
                    HRESULT hr = ::OleLoadPicture(pIstream, nPicFileBufSize, TRUE, IID_IPicture, (LPVOID*)&m_iPicture);
                    if (FAILED(hr))
                    {
                        TRACE("OleLoadPicture failed!!\n");
                        goto CLOSEFILE;
                    }
                    pIstream->Release();
                }
            }
            else
            {
                TRACE("lpData=NULL!!!\n");
                goto CLOSEFILE;
            }
        }
        else
        {
            TRACE("hGlobal=NULL!!!\n");
            goto CLOSEFILE;
        }

        // show the pic
        if (NULL != m_iPicture)
        {   
            CSize sizeInHimetric;   // pic size, metric system

            HRESULT hr = NULL;
            hr = m_iPicture->get_Width(&sizeInHimetric.cx);
            if (FAILED(hr))
            {
                TRACE("get_Width failed!!\n");
                goto CLOSEFILE;
            }
            hr = m_iPicture->get_Height(&sizeInHimetric.cy);
            if (FAILED(hr))
            {
                TRACE("get_Height failed!!\n");
                goto CLOSEFILE;
            }

            //himetric convert to inch, then inch to pixel

            HDC hDCScreen = ::GetDC(NULL);
            int nPixelsPerInchX = ::GetDeviceCaps(hDCScreen, LOGPIXELSX);
            int nPixelsPerInchY = ::GetDeviceCaps(hDCScreen, LOGPIXELSY);
            ::ReleaseDC(NULL, hDCScreen);

            CSize sizeInPixel;  // pic size, pixel system
            sizeInPixel.cx = MulDiv(sizeInHimetric.cx, nPixelsPerInchX, HIMETRIC_PER_INCH);
            sizeInPixel.cy = MulDiv(sizeInHimetric.cy, nPixelsPerInchY, HIMETRIC_PER_INCH);

            m_szPicPixel = sizeInPixel;
            m_szPicHimetric = sizeInHimetric;

            DrawPic();
        }
        
    CLOSEFILE:
        cFile.Close();
    }
    return;
}

// draw pic
void CTestLoadJPEGDlg::DrawPic()
{
    if (NULL == m_iPicture)
    {
        TRACE("m_iPicture=NULL!!\n");
        return;
    }

    CRect rect;
    m_staticPicRect.GetWindowRect(rect);
    
    // the left point
    CPoint ptTopLeft;
    ptTopLeft = rect.TopLeft();

    // zoom rate. [>1.0:zoom in, <1.0:zoom out] 
    float fZoomRate = 1.0;

    int   xSrcPos = (int)(ptTopLeft.x / fZoomRate);              
    int   ySrcPos = (int)(ptTopLeft.y / fZoomRate);            
    int   cxSrcWidth = (int)(rect.Width() / fZoomRate);          
    int   cySrcHeight = (int)(rect.Height() / fZoomRate);       
  
    CDC* dc = GetDC();
    int nPixelsPerInchX = ::GetDeviceCaps(*dc, LOGPIXELSX);
    int nPixelsPerInchY = ::GetDeviceCaps(*dc, LOGPIXELSY);

    // MulDiv(a,b,c) -> a*b/c

    // Horizontal   offset   in   source   picture
    int xHimetric = MulDiv(xSrcPos, HIMETRIC_PER_INCH, nPixelsPerInchX);   
    // Vertical   offset   in   source   picture   
    int yHimetric = MulDiv(ySrcPos, HIMETRIC_PER_INCH, nPixelsPerInchY);
    // Amount   to   copy   horizontally   in   source   picture
    int wHimetric = MulDiv(cxSrcWidth, HIMETRIC_PER_INCH, nPixelsPerInchX);
    // Amount   to   copy   vertically   in   source   picture   
    int hHimetric = MulDiv(cySrcHeight, HIMETRIC_PER_INCH, nPixelsPerInchY);

    HRESULT hr = m_iPicture->Render(dc->GetSafeHdc(), rect.left, rect.top, rect.Width(), rect.Height(), 
                xHimetric, yHimetric, wHimetric, hHimetric, NULL);

    if (FAILED(hr))
    {
        TRACE("Render failed!!\n");
        return;
    }
    TRACE("Render PIC SUC!!\n");
}


thks again!
AnswerRe: [please help]why i cannot render my pic?thks! Pin
Baltoro8-Nov-08 9:39
Baltoro8-Nov-08 9:39 
GeneralRe: [please help]why i cannot render my pic?thks! Pin
kaviniswell12-Nov-08 19:30
kaviniswell12-Nov-08 19:30 
AnswerRe: [please help]why i cannot render my pic?thks! Pin
Mark Salsbery9-Nov-08 6:55
Mark Salsbery9-Nov-08 6:55 
QuestionHow to create water ripple in directx? Pin
Md. Ali Naser Khan5-Nov-08 23:00
Md. Ali Naser Khan5-Nov-08 23:00 
AnswerRe: How to create water ripple in directx? Pin
El Corazon7-Nov-08 14:54
El Corazon7-Nov-08 14:54 
QuestionHi there :) Please help me Pin
viashivan5-Nov-08 5:02
viashivan5-Nov-08 5:02 
QuestionSave metafile as bitmap Pin
kildareflare4-Nov-08 23:29
kildareflare4-Nov-08 23:29 
AnswerRe: Save metafile as bitmap Pin
kildareflare5-Nov-08 23:02
kildareflare5-Nov-08 23:02 
QuestionStereo Cameras and OpenCV Pin
MikeMarq4-Nov-08 7:30
MikeMarq4-Nov-08 7:30 
AnswerRe: Stereo Cameras and OpenCV Pin
Tim Craig4-Nov-08 20:01
Tim Craig4-Nov-08 20:01 
GeneralRe: Stereo Cameras and OpenCV Pin
MikeMarq5-Nov-08 5:58
MikeMarq5-Nov-08 5:58 
GeneralRe: Stereo Cameras and OpenCV Pin
Tim Craig5-Nov-08 8:04
Tim Craig5-Nov-08 8:04 
GeneralRe: Stereo Cameras and OpenCV Pin
Tim Craig5-Nov-08 22:41
Tim Craig5-Nov-08 22:41 
GeneralRe: Stereo Cameras and OpenCV Pin
MikeMarq7-Nov-08 7:38
MikeMarq7-Nov-08 7:38 
GeneralRe: Stereo Cameras and OpenCV Pin
Tim Craig7-Nov-08 13:32
Tim Craig7-Nov-08 13:32 
GeneralRe: Stereo Cameras and OpenCV Pin
MikeMarq8-Nov-08 9:07
MikeMarq8-Nov-08 9:07 
GeneralRe: Stereo Cameras and OpenCV Pin
Tim Craig8-Nov-08 14:50
Tim Craig8-Nov-08 14:50 

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.