Skip to main content
Known Participant
April 9, 2011
Question

how to place a image in a page?

  • April 9, 2011
  • 1 reply
  • 676 views

pls anyone guide me? how to place a image in a page?

thanks,

screen410099

This topic has been closed for replies.

1 reply

JADarnell
Inspiring
April 9, 2011

Take a look at the code found in this function:

SDKLayoutHelper::PlaceFileInFrame

As expected you can find it in the SDKLayoutHelper file usually found in the Common folder of the SDK.  Anyway it has an example of one way of achieving your goal.

There are other ways as well.  Here is some code from one of my plugins which uses the LoadPlaceGunCmd boss:

          PMRect pRC = itemGeometry -> GetPathBoundingBox(InnerToPasteboardMatrix(pParentTransform));;

          // Create an ImportCmd:
          InterfacePtr<ICommand> importAndLoadPlaceGunCmd(CmdUtils::CreateCommand(kImportAndLoadPlaceGunCmdBoss));

          //InterfacePtr<ICommand> importAndLoadPlaceGunCmd(CmdUtils::CreateCommand(kImportFileCmdBoss));
          if (importAndLoadPlaceGunCmd == nil)
          {
              ASSERT_FAIL("importAndLoadPlaceGunCmd invalid");
              break;
          }

            URI URIPath;
            URIUTILS -> IDFileToURI(path, URIPath);

          // Set the IImportResourceCmdData Interface's data:
          InterfacePtr<IImportResourceCmdData> importFileCmdData(importAndLoadPlaceGunCmd, IID_IIMPORTRESOURCECMDDATA);
          if (importFileCmdData == nil)
          {
              ASSERT_FAIL("importFileCmdData invalid");
              break;
          }

          importFileCmdData -> Set(db, URIPath, (K2::UIFlags)0, kTrue, kFalse);
          ErrorCode status = CmdUtils::ProcessCommand(importAndLoadPlaceGunCmd);

          const UIDList* imageList = importAndLoadPlaceGunCmd -> GetItemList();
          if (!imageList || imageList -> Length() == 0)
              break;

          UIDRef imageFrame = imageList -> GetRef(0);
          InterfacePtr<IHierarchy> imageFrameHierarchy(imageFrame, UseDefaultIID());

          UIDRef newImage(db, imageFrameHierarchy -> GetChildUID(0));

          imageFrameHierarchy -> Remove(imageFrameHierarchy -> GetChildUID(0));

          // Create an placeGraphicCmd:
          InterfacePtr<ICommand> placeGraphicCmd(CmdUtils::CreateCommand(kPlaceItemInGraphicFrameCmdBoss));
          if (placeGraphicCmd == nil)
          {
              ASSERT_FAIL("placeGraphicCmd invalid");
              break;
          }
          placeGraphicCmd -> SetItemList(UIDList(newImage));

          // Set the IPlacePIData Interface's data:
          InterfacePtr<IPlacePIData> placePIData(placeGraphicCmd, IID_IPLACEPIDATA);
          if (placePIData == nil)
          {
              ASSERT_FAIL("placePIData invalid");
              break;
          }
          placePIData -> Set(pageItemRef, nil, kFalse);
          // Process the ImportAndPlaceCmd:
          status = CmdUtils::ProcessCommand(placeGraphicCmd);

HTH.

John

Known Participant
April 11, 2011

Hi JADarnell,

               your code is work fine,but fit to frame is not work,pls help

thanks,

screen410099