GDI+ question Im kindda stuck
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: GDI+ question Im kindda stuck

  1. #1
    Join Date
    Apr 2012
    Posts
    2

    GDI+ question Im kindda stuck

    Hi forum
    I have a task of sending a graphics object to a printer, but I am facing some challenges.

    It has to be Device independant and I hav reached quite far in my development.

    However i am facing some issues.. I know that text and graphics works totally independant in my solution, and I am managing to scale and resize my graphics correct as long i am using devices(printers) over 300 dpi. using below 300 dpi my graphics is cut accordingly eg 150 will give me the right dimensions but the graphics is cut down to 50%.

    Second challenge i am facing is when i am uising odd device dpi, meaning a dpi that will give a decimal when devided by 300. When using a dpi where the result is a full figure when deviding by 300 i can align my text perfect, but when the odd figure is the result my text starts floading on page 2,3 ect.


    Below is the code that i have added to the solution. (plz dont laugh im new to c++)

    Setting the graphics object (vector)
    //start
    mp_oControl->iPrintXOrig = XOrigin;
    mp_oControl->iPrintYOrig = YOrigin;
    CDC *pDC = CDC::FromHandle ((HDC)hdc);
    pDC->SetMapMode(MM_TEXT);
    oGraphics.TranslateTransform(-(REAL)XOrigin,-(REAL)YOrigin);

    oGraphics.ScaleTransform((REAL)DestScale / (REAL)100, (REAL)DestScale / (REAL)100);

    oGraphics.SetPageUnit(UnitPixel);

    oGraphics.SetPageScale(int(oGraphics.GetDpiX()/mp_oControl->iGlobalPixelsY));

    //end


    //moving my text according to dpi on the device
    //start
    ScaleFactorDPI = 1;

    if (mp_oControl->globalDPIScale)
    ScaleFactorDPI = mp_oControl->globalDPIScale;
    // global dpi scale is LOGPIXELSY/300

    if (ScaleFactorDPI !=1)
    {
    double lMulfactor = (float)(mp_oControl->iGlobalPixelsY/300)-1;



    double iXorg = mp_oControl->GetMathLib()->RoundDouble((mp_oControl->iPrintXOrig*lMulfactor));
    double iYorg = mp_oControl->GetMathLib()->RoundDouble((mp_oControl->iPrintYOrig*lMulfactor));

    v_lLeft = (v_lLeft*ScaleFactorDPI)-iXorg;
    v_lTop = (v_lTop*ScaleFactorDPI)-iYorg;
    v_lRight = (v_lRight*ScaleFactorDPI)-iXorg;
    v_lBottom = (v_lBottom*ScaleFactorDPI)-iYorg;

    }//end

  2. #2
    Join Date
    Jan 2009
    Posts
    596

    Re: GDI+ question Im kindda stuck

    Quote Originally Posted by djmasterp View Post
    Second challenge i am facing is when i am uising odd device dpi, meaning a dpi that will give a decimal when devided by 300. When using a dpi where the result is a full figure when deviding by 300 i can align my text perfect, but when the odd figure is the result my text starts floading on page 2,3 ect.
    You casting to an int here:
    Code:
    oGraphics.SetPageScale(int(oGraphics.GetDpiX()/mp_oControl->iGlobalPixelsY));
    when you don't need to - SetPageScale takes a REAL, not an int. Could this be what is causing the problem?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center