Re: BITMAP & grid

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



On Sat, 16 Apr 2005 13:19:47 +0900, "William"
<port@xxxxxxxxxxxxxxxxxx> wrote:

>Thanks Severian,
>
>I just tried. With Rectangle(), I can draw the gird but the interior of the
>rectangle also is painted.
>
>If I use FrameRect(), it doesn't work. The following is my source.
>
>void CMyView::OnDraw(CDC* pDC)
>{
> CBitmap bm;
> bm.LoadBitmap(IDB_BITMAP8); //8 pixcel * 8 pixcel as attached.
>
> // Create a pattern brush from the bitmap.
> CBrush cBrPattern;
> cBrPattern.CreatePatternBrush(&bm);
>
> // Select the brush into a device context, and draw.
> CBrush* pOldBrush = (CBrush*)pDC->SelectObject(&cBrPattern);
> CPen* pOldPen;
> pOldPen = (CPen*)pDC->SelectStockObject(NULL_PEN);
>
> // pDC->Rectangle(CRect(50, 50, 200, 200));
> pDC->FrameRect(CRect(50, 50, 200, 200), &cBrPattern);
>
> //Restore the original brush.
> pDC->SelectObject(pOldBrush);
> pDC->SelectObject(pOldPen);
>}
>
>Please help
>William
>
>> LineDDA calls back to your code for every point on the line (and
>> you're calling SetPixel), which is making it slow.
>>
>> I would try FrameRect() with a patterned brush.

The pattern needs to fill the bitmap area like a checkerboard.

x0x0x0x0
0x0x0x0x

etc.

I would draw rectangles similarly to the way you are drawing the
lines: a bunch of tall, narrow ones followed by a bunch of wide, short
ones. For the outside border, like MSPoaint, follow with a full
rectangle around the entire area.

--
Phillip Crews aka Severian
Microsoft MVP, Windows SDK
Posting email address is real, but please post replies on the newsgroup.
.



Relevant Pages

  • Re: API Drawing, hatch, can I orient the hatch?
    ... I'm using a hatch to draw this rectangle. ... > Maybe what I'm looking for is the ability to draw create a custom hatch? ... In answer to your question though, yes you can create a pattern brush from any Bitmap so you could just draw your rotated hatch ...
    (microsoft.public.vb.general.discussion)
  • Re: API Drawing, hatch, can I orient the hatch?
    ... I'm using a hatch to draw this rectangle. ... > Maybe what I'm looking for is the ability to draw create a custom hatch? ... In answer to your question though, yes you can create a pattern brush from any Bitmap so you could just draw your rotated hatch ...
    (microsoft.public.vb.winapi.graphics)
  • Re: BITMAP & grid
    ... With Rectangle(), I can draw the gird but the interior of the ... If I use FrameRect(), it doesn't work. ... // Create a pattern brush from the bitmap. ...
    (microsoft.public.win32.programmer.gdi)
  • Moving rectangle around StringGrid
    ... I am trying to move a rectangle around on a StringGrid. ... I can draw the ... rectangle using FrameRect, but I end up with many rectangles as I move it. ...
    (comp.lang.pascal.delphi.misc)
  • RE: GDI+ Clip Region allows 0.0f width pen to draw through
    ... Just to make this more outrageous if you draw the vertical lines from the ... I took the previous code I posted and made the panel anchor to all four ... private void panel1_SizeChanged ... In other words create a rectangle that is a wider than the panel. ...
    (microsoft.public.win32.programmer.gdi)