Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / CodeWarrior / August 2003



Tip: Looking for answers? Try searching our database.

How to copy an pane's imaage to a PicHandle?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mark Dawson - 25 Aug 2003 06:47 GMT
I want to copy what's in a pane's image to a PicHandle 9for later export
to the scrap).  I seem to be copying the dest rect correctly, but the
data isn't showing up.  I've tried both copying srcRect to srcRect &&
(what's shown) srcRect to a 0,0 based rect.  Neither seems to help.  Can
anyone see what I may be doing wrong? I'm running on 10.2.6 & CW 8.3, if
that makes a differenceŠ

Thanks!
Mark
marc@mac.com
----
Notes:
(a) ST_Rect wraps a Rect
(b) StGWorldPtrSaver locks a GWorldPtr
(c) m_GLPane is the pane that I want the image of

PicHandle picHandle(NULL);
ST_Rect bounds;
WindowPtr windowPtr = m_GLPane->GetMacWindow();

m_GLPane->CalcPortFrameRect(bounds);

{
  ST_Rect offsetBounds(bounds);
  offsetBounds.OffsetX(-bounds.top);
  offsetBounds.OffsetY(-bounds.left);
  LGWorld * newGWorld  = new LGWorld(offsetBounds, 32);
  if (newGWorld)
  {
     GWorldPtr  outGWorldPtr = newGWorld->GetMacGWorld();
     const BitMap *aBitMap =
GetPortBitMapForCopyBits(GetWindowPort(windowPtr));
     const BitMap *outBitMap = GetPortBitMapForCopyBits(outGWorldPtr);
     {
        StGWorldPtrSaver outGWorldSaver(outGWorldPtr);
     
        picHandle = OpenPicture(&bounds);
        CopyBits(   aBitMap, outBitMap, &bounds, &offsetBounds,
srcCopy, 0L);
 
           ClosePicture();
        }
        UScrap::SetData(kScrapFlavorTypePicture, *picHandle,
GetHandleSize((Handle)picHandle), true);
     
     delete newGWorld;
  }
}
David Phillip Oster - 25 Aug 2003 07:36 GMT
> I want to copy what's in a pane's image to a PicHandle 9for later export
> to the scrap).  I seem to be copying the dest rect correctly, but the
> data isn't showing up.  I've tried both copying srcRect to srcRect &&
> (what's shown) srcRect to a 0,0 based rect.  Neither seems to help.  Can
> anyone see what I may be doing wrong? I'm running on 10.2.6 & CW 8.3, if
> that makes a differenceŠ

You may need to use glReadPixels() to read the pixels from the OpenGL
framebuffer, then copy them, one scan line at a time, to an appropriate
GWorld. Then, your code may work.
Mark Dawson - 25 Aug 2003 17:20 GMT
> > I want to copy what's in a pane's image to a PicHandle 9for later export
> > to the scrap).  I seem to be copying the dest rect correctly, but the
[quoted text clipped - 6 lines]
> framebuffer, then copy them, one scan line at a time, to an appropriate
> GWorld. Then, your code may work.

Looks like that this is the problem--I taking a snapshot of a GL context
doesn't work directly--it wasn't that my code was copying wrong, but
that it was important that the pane was a OpenGL pane (I didn't realize
that it made a difference).

Thanks!  I'll look into thisŠ

Mark
Jon Summers - 25 Aug 2003 08:03 GMT
> data isn't showing up.  I've tried both copying srcRect to srcRect &&
> (what's shown) srcRect to a 0,0 based rect.  Neither seems to help.  Can
> anyone see what I may be doing wrong? I'm running on 10.2.6 & CW 8.3, if
> that makes a differenceŠ

It is an off-by-one error in the number of GWorlds required :-)

You don¹t need the temporary destination GWorld.
Record the Picture by blitting the pane's bit of the window onto itself.

m_GLPane->FocusDraw();// remember to focus on the pane...
m_GLPane->CalcPortFrameRect(bounds);

OpenCPicParams    ocpp;
std::memset(&ocpp, 0, sizeof(OpenCPicParams));
ocpp.srcRect = bounds;
ocpp.hRes = ocpp.vRes = (72L << 16);
ocpp.version = 2;

picHandle = ::OpenCPicture(&ocpp);
const BitMap *aBitMap =
   ::GetPortBitMapForCopyBits(::GetWindowPort(GLPane->GetMacWindow()));
::CopyBits(aBitMap, aBitMap, &bounds, &bounds, srcCopy, 0L);
::ClosePicture();

Signature

   jons(AT)vrtools(DOT)com

David Phillip Oster - 25 Aug 2003 16:11 GMT
> > data isn't showing up.  I've tried both copying srcRect to srcRect &&
> > (what's shown) srcRect to a 0,0 based rect.  Neither seems to help.  Can
[quoted text clipped - 16 lines]
>
> picHandle = ::OpenCPicture(&ocpp);

ClipRect(&bounds); // <-------- don't forget this.

> const BitMap *aBitMap =
>     ::GetPortBitMapForCopyBits(::GetWindowPort(GLPane->GetMacWindow()));
> ::CopyBits(aBitMap, aBitMap, &bounds, &bounds, srcCopy, 0L);
> ::ClosePicture();

If you are reusing your original window, remember to set the ClipRect
appropriately, or a large PICT may be clipped.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.