copy a wxDC to wxScrolledWindow

Miguel Cartagena miguel.cartagena at gmail.com
Wed Dec 6 05:22:58 PST 2006


Nothing??
Any idea??

Regards,

Miguel


On 5 dez, 14:21, "Miguel Cartagena" <miguel.cartag... at gmail.com> wrote:
> Sorry, I didn't has time t explain before, so ...
>
> The source DC comes from another module of my application, where it's
> drawn. In my module, I have to show this DC on screen (using a
> wxScrolledWindow for that).
>
> Now I'm do this in this way:
>  1 - I'm receive a pointer to the source DC and store a static pointer
> of a wxBitmap.
>
>         wxBitmap* DocToCanvasMapper::BitmapInstance(wxDC &dc){
>         static wxBitmap *bmp = 0;
>         if (!bmp) {
>           int w, h;
>           dc.GetSize(&w, &h);
>           bmp = new wxBitmap(w, h);
>           wxMemoryDC *memDC = new wxMemoryDC();
>           memDC->SelectObject(*bmp);
>           wxCoord zero = 0;
>           wxCoord ww = w;
>           wxCoord hh = h;
>
>           memDC->Blit(zero, zero, ww, hh, dcc, zero, zero);
>           dc.DrawBitmap(*bmp, zero, zero, true);
>           bmp->SaveFile(_T("/home/miguel/Desktop/test.bmp"),
> wxBITMAP_TYPE_BMP);
>           memDC->SelectObject(wxNullBitmap);
>           delete memDC;
>         }
>         return bmp;
>
> } 2 - Rewrinting the wxScrolledWindow::OnDraw() method, I call the bmp
> pointer and draw on a dc.
>   void MyScrolledWindow::Draw(wxDC& dc){
>     wxImage img =
> DocToCanvasMapper::BitmapInstance()->ConvertToImage();
>     img.Rescale(630, 891);
>     wxBitmap bmpRescaled(img);
>     dc.DrawBitmap(bmpRescaled, 0, 0, true);
>   }
>
> To test, I'm using another wxScrolledWindow (SWTest), drawing on it
> rewriting the OnDraw method, putting the SW on a frame and show it. To
> send the SWTest DC to my module I do this:
> wxDC* SWTest::GetDC(){
>   return new wxClientDC(this);
>
> }Well ... the problem that I have is: When the wxBitmap is generated the
> image that is build is like a print screen, cutting the area where the
> SWTest is.
>
> On 4 dez, 16:41, "Miguel Cartagena" <miguel.cartag... at gmail.com> wrote:
>
> > The source DC come from another module and is drawn manually. Something
> > like this:
>
> > void BuildDC(){
> >   wxClientDC dc(this);
> >   dc.DrawText(_T("TEST"), 10, 10);
> >   ...
>
> > }On Dec 4, 10:55 am, pstarczew... at o2.pl (Piotr Starczewski) wrote:
>
> > > Your code looks ok (didn't test it yet). The only thing is that you
> > > should put memDC->SelectObject(wxNullBitmap) instead of
> > > memDC->DrawBitmap. By drawing your bitmap on memDC theoretically you are
> > > drawing currently selected bitmap on the same bitmap (I'm not sure if
> > > that is possible with currently drawn bitmap selected into wxMemoryDC
> > > and I'm not sure how it will behave). I'll test this solution later this
> > > evening.
>
> > > You mentioned that "I have a wxDC drawn before, outside my
> > > application.". What do you mean by that? Are you trying to take a window
> > > snapshot from external application or does some external application
> > > "draws" on your dc?
>
> > > Regards,
> > > Peter
>
> > > Miguel Cartagena wrote:
> > > > I test this and when I call Blit method, it's draw a print screen .. my
> > > > IDE.
> > > > Here the code:
>
> > > >   dc.GetSize(&w, &h);
> > > >           // the source DC
> > > >   wxBitmap bmp(w, h, wxBITMAP_TYPE_BMP);
> > > >   wxMemoryDC *memDC = new wxMemoryDC();
> > > >   memDC->SelectObject(bmp);
> > > >   bmp.SaveFile(_T("c:\\test1.bmp"), wxBITMAP_TYPE_BMP);    // just for
> > > > test
> > > >   wxCoord zero = 0;
> > > >   wxCoord ww = w;
> > > >   wxCoord hh = h;
>
> > > >   memDC->Blit(zero, zero, ww, hh, &dc, zero, zero);
> > > >   bmp.SaveFile(_T("c:\\test2.bmp"), wxBITMAP_TYPE_BMP);   // just for
> > > > test
>
> > > >   memDC->DrawBitmap(bmp, 0, 0, false);
>
> > > >   wxImage img = bmp.ConvertToImage();
> > > >   img.Rescale(210, 297);
> > > >   wxBitmap bmpRescaled(img);
>
> > > >   bmpRescaled.SaveFile(_T("c:\\test3.bmp"), wxBITMAP_TYPE_BMP);   //
> > > > just for test
>
> > > > On Dec 4, 9:56 am, pstarczew... at o2.pl (Piotr Starczewski) wrote:
>
> > > >> That should not be a problem. First of all you need to get a
> > > >> pointer/reference to your source wxDC. Then just wxDC::Blit it into
> > > >> wxMemoryDC with selected bitmap. Final step is to rescale your bitmap
> > > >> and draw it with wxDC::DrawBitmap(...) onto your scrolled window.
>
> > > >> Regards,
> > > >> Peter
>
> > > >> Miguel Cartagena wrote:
>
> > > >>> Sorry, I'll try to explain the problem better.
>
> > > >>> I have a wxDC drawn before, outside my application. So, I don't know
> > > >>> what is drawn in it and I can't "do my drawing"  :)
> > > >>> What I want to do is: get this DC, rescale to my ScrolledWindow size
> > > >>> and show it into my ScrolledWindow.
>
> > > >>> For this, copy the DC it's not enough, I think. A possible solution is
> > > >>> redraw the DC that I receive on MyScrolledWindow::OnDraw(wxDC& dc)
> > > >>> method, or something like.
>
> > > >>> void DCReceiver::ReceiveDC(wxDC& dc){
> > > >>>   MyScrolledWindow::Draw(dc);
> > > >>> }
>
> > > >>> ...
>
> > > >>> void MyScrolledWindow::Draw(wxDC& dc){
> > > >>>   dc.Redraw();  // the wxDC::Redraw() method not exists, therefore my
> > > >>> doubt.
> > > >>> }
>
> > > >>> void MyScrolledWindow::OnDraw(wxDC& dc){
> > > >>>   Draw(dc);  // rewrite the wxScrolledWindow::OnDraw method ?
> > > >>> }
>
> > > >>> Thanks and regards,
> > > >>> Miguel
>
> > > >>> ---------------------------------------------------------------------
> > > >>> To unsubscribe, e-mail: wx-users-unsubscr... at lists.wxwidgets.org
> > > >>> For additional commands, e-mail: wx-users-h... at lists.wxwidgets.org---------------------------------------------------------------------
>
> > > >> To unsubscribe, e-mail: wx-users-unsubscr... at lists.wxwidgets.org
> > > >> For additional commands, e-mail: wx-users-h... at lists.wxwidgets.org
>
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: wx-users-unsubscr... at lists.wxwidgets.org
> > > > For additional commands, e-mail: wx-users-h... at lists.wxwidgets.org---------------------------------------------------------------------
> > > To unsubscribe, e-mail: wx-users-unsubscr... at lists.wxwidgets.org
> > > For additional commands, e-mail: wx-users-h... at lists.wxwidgets.org







More information about the wx-users mailing list