Board index » Visual Studio » CBrush(*CBitmap) Texture Brush Printing Issue.

CBrush(*CBitmap) Texture Brush Printing Issue.

Visual Studio323
Question is: What can I do to make sure that when printing in Landscape that

a CBrush (Texture Brush) will not overlap, but tile correctly as it does in

Portrait mode?



Here is the sample code:



//Temp Device COntext

CDC dcTemp;

CBitmap bmp;



//Create the Bitmap Texture (nScaleFactor is global)

bmp.CreateCompatibleBitmap(pDC,20*nScaleFactor,20*nScaleFactor);



//Create compatible DC

dcTemp.CreateCompatibleDC(pDC);



//Select the Bitmap into the temp DC

oldBMP = dcTemp.SelectObject(&bmp);



//Draw the Bitmap Texture

RECT rc;

CBrush brushWhite(RGB(255,255,255));

dcTemp.GetClipBox(&rc);



//Make the actual Texture pattern. In this case, just a circle

dcTemp.FillRect(&rc, &brushWhite);

dcTemp.Ellipse(&rc);

dcTemp.SelectObject(oldBMP);



//Create a Texture brush using the Bitmap above

CBrush brush4(&bmp);



//Select the Texture Brush in the current DC

pOldBrush = pDC->SelectObject(&brush4);



//Paint with Tecture bitmap (200X200 Square)

pDC->Rectangle(100*nScaleFactor,100*nScaleFactor,300*nScaleFactor,300*nScale

Factor);



This prints fine in "Portrait" mode, but in Landscape, the texture is not

tiled correctly. There is overlapping of the texture.

Please NOTE: 'nScaleFactor' is used to scale the draw such that it prints

the right size on the printer (is 1 when in running mode, and ranges from 2

to 8 when printing depending on the DPI of printer used)



This is adjusted in the OnPrint() Method:



//m_rcPaper is a CRect sized to a 8.5" X 11" paper (850,1100)

m_fZoomFactor = (float)pInfo->m_rectDraw.Width()/m_rcPaper.Width();



Thanks,

Joe


-
 

Re:CBrush(*CBitmap) Texture Brush Printing Issue.

Joe,



Personally, I would have tiled the brush myself, but that's just me being a

control-freak. You might wat to experiment with the following (taken from

MSDN, UnrealizeObject in the SDK): UnrealizeObject, SetBrushOrgEx, and

SelectObject on the brush.



Johan Rosengren

Abstrakt Mekanik AB



"PinHead" <PinHead@somedomain.com>a écrit dans le message de

Quote
Question is: What can I do to make sure that when printing in Landscape

that

a CBrush (Texture Brush) will not overlap, but tile correctly as it does

in

Portrait mode?



Here is the sample code:



//Temp Device COntext

CDC dcTemp;

CBitmap bmp;



//Create the Bitmap Texture (nScaleFactor is global)

bmp.CreateCompatibleBitmap(pDC,20*nScaleFactor,20*nScaleFactor);



//Create compatible DC

dcTemp.CreateCompatibleDC(pDC);



//Select the Bitmap into the temp DC

oldBMP = dcTemp.SelectObject(&bmp);



//Draw the Bitmap Texture

RECT rc;

CBrush brushWhite(RGB(255,255,255));

dcTemp.GetClipBox(&rc);



//Make the actual Texture pattern. In this case, just a circle

dcTemp.FillRect(&rc, &brushWhite);

dcTemp.Ellipse(&rc);

dcTemp.SelectObject(oldBMP);



//Create a Texture brush using the Bitmap above

CBrush brush4(&bmp);



//Select the Texture Brush in the current DC

pOldBrush = pDC->SelectObject(&brush4);



//Paint with Tecture bitmap (200X200 Square)



pDC->Rectangle(100*nScaleFactor,100*nScaleFactor,300*nScaleFactor,300*nScale

Factor);



This prints fine in "Portrait" mode, but in Landscape, the texture is not

tiled correctly. There is overlapping of the texture.

Please NOTE: 'nScaleFactor' is used to scale the draw such that it prints

the right size on the printer (is 1 when in running mode, and ranges from

2

to 8 when printing depending on the DPI of printer used)



This is adjusted in the OnPrint() Method:



//m_rcPaper is a CRect sized to a 8.5" X 11" paper (850,1100)

m_fZoomFactor = (float)pInfo->m_rectDraw.Width()/m_rcPaper.Width();



Thanks,

Joe









-

Re:CBrush(*CBitmap) Texture Brush Printing Issue.

Thanks again Johan.

Lots of good info there.. I found what I was looking for.



"Johan Rosengren" <johan.rosengren@telia.com>wrote in message

Quote
Joe,



Personally, I would have tiled the brush myself, but that's just me being

a

control-freak. You might wat to experiment with the following (taken from

MSDN, UnrealizeObject in the SDK): UnrealizeObject, SetBrushOrgEx, and

SelectObject on the brush.



Johan Rosengren

Abstrakt Mekanik AB



"PinHead" <PinHead@somedomain.com>a écrit dans le message de

news:etbuvTGNEHA.936@TK2MSFTNGP11.phx.gbl...

>Question is: What can I do to make sure that when printing in Landscape

that

>a CBrush (Texture Brush) will not overlap, but tile correctly as it does

in

>Portrait mode?

>

>Here is the sample code:

>

>//Temp Device COntext

>CDC dcTemp;

>CBitmap bmp;

>

>//Create the Bitmap Texture (nScaleFactor is global)

>bmp.CreateCompatibleBitmap(pDC,20*nScaleFactor,20*nScaleFactor);

>

>//Create compatible DC

>dcTemp.CreateCompatibleDC(pDC);

>

>//Select the Bitmap into the temp DC

>oldBMP = dcTemp.SelectObject(&bmp);

>

>//Draw the Bitmap Texture

>RECT rc;

>CBrush brushWhite(RGB(255,255,255));

>dcTemp.GetClipBox(&rc);

>

>//Make the actual Texture pattern. In this case, just a circle

>dcTemp.FillRect(&rc, &brushWhite);

>dcTemp.Ellipse(&rc);

>dcTemp.SelectObject(oldBMP);

>

>//Create a Texture brush using the Bitmap above

>CBrush brush4(&bmp);

>

>//Select the Texture Brush in the current DC

>pOldBrush = pDC->SelectObject(&brush4);

>

>//Paint with Tecture bitmap (200X200 Square)

>



pDC->Rectangle(100*nScaleFactor,100*nScaleFactor,300*nScaleFactor,300*nScale

>Factor);

>

>This prints fine in "Portrait" mode, but in Landscape, the texture is

not

>tiled correctly. There is overlapping of the texture.

>Please NOTE: 'nScaleFactor' is used to scale the draw such that it

prints

>the right size on the printer (is 1 when in running mode, and ranges

from

2

>to 8 when printing depending on the DPI of printer used)

>

>This is adjusted in the OnPrint() Method:

>

>//m_rcPaper is a CRect sized to a 8.5" X 11" paper (850,1100)

>m_fZoomFactor = (float)pInfo->m_rectDraw.Width()/m_rcPaper.Width();

>

>Thanks,

>Joe

>

>









-