Re: Memory problems, I think...

From: Mike D Sutton (EDais_at_mvps.org)
Date: 09/29/04


Date: Wed, 29 Sep 2004 20:08:04 +0100


> Good, because I'm using it extensively. <g> And for ChromaBlt (yup, got that
> one from you, too) I don't think I'll need it...not quite sure yet, still trying
> to work it out in my head.

Nope, from what you've described you shouldn't need it in this situation.

> So, what I'd do in my situation is this:
>
> First, I'd load the awkwardly large .tif file using the lead control just like I
> do now.
>
> I'd then create an enhanced metafile with the same dimensions as the source
> image (now as a bitmap held in memory by the lead control...I dont' have any
> control over that.).
>
> From there, I can draw rectangles, circles, etc. into the .emf file. This is
> where I lose it. I understand that I'll have a DC and it will be used in the
> same way that I'm using a bitmap DC right now, by drawing using api calls that
> take a DC as an argument, but is this where it is going to take up less memory?
> So, creating a bitmap in memory that is 15000x10000 pixels takes up more memory
> than an .emf that uses the same width and height?

Remember that when you draw to a normal DC, you're not actually drawing to the DC itself (it's merely a container) but to the Bitmap
that's selected within it. In the same way when you draw to a MetaDC you draw to it's internal EMF which is nothing more than a
list of API drawing commands that have been fired at it.
Since your EMF simply records the drawing calls rather than actually rasterising them, creating EMF's is _very_ fast with very
little overhead since you don't require any kind of drawing surface (Bitmap) or have to rasterise the shapes as you draw them.

> Assuming the above, when I goto draw on screen what the user wants to see (just
> a small rectangle out of both images) I'll already have a small (same size as
> picturebox on screen) DC and bitmap in memory.
>
> I then stretchblt (taking into account zoom factors) from the leadcontrol (ie,
> the source floorplan image) to the small memory DC,
>
> Then stretchblt out of my EMF file the same dimensions (at which time I guess
> the EMF actually, what's the word, "realizes" the drawing instructions I've
> given it, hopefully only the ones that need to be realized, onto the same small
> memory DC.

You can't draw only a segment of an EMF to a DC in the same way as Bit/StretchBlt() allows you to specify a source rectangle,
however GDI clipping will simply not draw anything that lies outside the visible area of the control. Rendering is a little slower
because the vector shapes have to be rasterised every time rather than just being drawn from a back-buffer as with your current
solution but it shouldn't be a problem unless you're using a very large number of shapes.

> Once I have that, then I BitBlt from the small memory DC to the picturebox on
> screen.

Yup, performing your drawing on a memory DC is a must with EMF's since they will flicker horribly as each shape is drawn if going
straight to the screen.

> And this all happens really really fast. I'm sure it does because I'm able to
> do this same type of situation with regular old memory bitmaps and DCs, and
> there isn't any slowness. It just crashes trying to CREATE the bitmaps in the
> first place. <g>

*Fingers crossed* Nah, you shouldn't have any problems with it :)

> Anyway, if you have time to give me a nod or a smack I'd love to take them both.

Hopefully the above is what you were after, once you've made the conceptual leap of realising that a MetaDC is really nothing more
special than a standard memory DC it should all fit into place and you'll wonder what the problem was!
Hope this helps,

    Mike

 - Microsoft Visual Basic MVP -
E-Mail: EDais@mvps.org
WWW: http://EDais.mvps.org/



Relevant Pages

  • Re: Drawing on DC
    ... class Circle: public Drawing { ... It would be *called* from OnDraw, ... You should only draw when you need to draw, ... Drawing your objects on a bitmap merely renders the circle, rectangle, etc. as bits (which ...
    (microsoft.public.vc.mfc)
  • Re: Drawing to a Bitmap
    ... called I simply blit the bitmap in memory to the screen. ... than to loop through everything and draw every item each time a WM_PAINT is ... other windows, though if this proves to be too difficult, a screenshot ...
    (microsoft.public.vc.mfc)
  • Re: CView and bitmap problem
    ... "Scoots" wrote in message ... Please do not immediately dismiss this as a "put drawing code ... I can even draw bitmaps. ... However, when a window ocludes the bitmap, it is not refreshed, even ...
    (microsoft.public.vc.mfc)
  • CView and bitmap problem
    ... Please do not immediately dismiss this as a "put drawing code ... I can even draw bitmaps. ... However, when a window ocludes the bitmap, it is not refreshed, even ... rectangle anytime I draw it (yes, ...
    (microsoft.public.vc.mfc)
  • Re: One thing I noticed
    ... >I did a test drawing 10,000 lines using vb code, it didn't draw to the ... >Out of the 3 methods (drawing direct to screen, drawing to bitmap or using ... >autoredraw) it is always the least efficient. ... - if one did an audit on Windows memory usage ... ...
    (microsoft.public.vb.general.discussion)

Loading