本文整理汇总了C++中CG32bitImage::Create方法的典型用法代码示例。如果您正苦于以下问题:C++ CG32bitImage::Create方法的具体用法?C++ CG32bitImage::Create怎么用?C++ CG32bitImage::Create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CG32bitImage
的用法示例。
在下文中一共展示了CG32bitImage::Create方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CopyGalacticMapToClipboard
void CopyGalacticMapToClipboard (HWND hWnd, CGalacticMapPainter *pPainter)
{
// Save some parameters
RECT rcOldView = pPainter->GetViewport();
int xOldCenter, yOldCenter;
pPainter->GetPos(&xOldCenter, &yOldCenter);
int iOldScale = pPainter->GetScale();
// Compute the size of the map
RECT rcView;
rcView.left = 0;
rcView.top = 0;
rcView.right = pPainter->GetWidth();
rcView.bottom = pPainter->GetHeight();
// Create a bitmap of the appropriate size
CG32bitImage FullMap;
FullMap.Create(RectWidth(rcView), RectHeight(rcView));
// Paint
pPainter->SetViewport(rcView);
pPainter->SetScale(100);
pPainter->SetPos(0, 0);
pPainter->Paint(FullMap);
// Copy to cliboard
FullMap.CopyToClipboard();
// Restore
pPainter->SetScale(iOldScale);
pPainter->SetViewport(rcOldView);
pPainter->SetPos(xOldCenter, yOldCenter);
}
示例2: GenerateSnapshot
void GenerateSnapshot (CUniverse &Universe, CXMLElement *pCmdLine)
{
ALERROR error;
int i;
// Get some parameters
int iInitialUpdateTime = pCmdLine->GetAttributeIntegerBounded(CONSTLIT("initialUpdate"), 0, -1, 10);
int iUpdateTime = pCmdLine->GetAttributeInteger(CONSTLIT("wait"));
bool bObjOnly = pCmdLine->GetAttributeBool(CONSTLIT("objOnly"));
// Criteria
CString sNode = pCmdLine->GetAttribute(CONSTLIT("node"));
CString sCriteria = pCmdLine->GetAttribute(CONSTLIT("criteria"));
// Number of snapshots
int iTotalCount = pCmdLine->GetAttributeIntegerBounded(CONSTLIT("count"), 1, -1, 1);
// Output
int cxWidth;
int cyHeight;
if (pCmdLine->FindAttributeInteger(CONSTLIT("size"), &cxWidth))
{
cyHeight = cxWidth;
}
else
{
cxWidth = 1024;
cyHeight = 1024;
}
// Paint flags
DWORD dwPaintFlags = 0;
if (pCmdLine->GetAttributeBool(CONSTLIT("noStars")))
dwPaintFlags |= CSystem::VWP_NO_STAR_FIELD;
// Output file
CString sFilespec = pCmdLine->GetAttribute(CONSTLIT("output"));
if (!sFilespec.IsBlank())
sFilespec = pathStripExtension(sFilespec);
// Output image
CG32bitImage Output;
Output.Create(cxWidth, cyHeight);
// Update context
SSystemUpdateCtx Ctx;
Ctx.bForceEventFiring = true;
Ctx.bForcePainted = true;
RECT rcViewport;
rcViewport.left = 0;
rcViewport.top = 0;
rcViewport.right = cxWidth;
rcViewport.bottom = cyHeight;
// Loop over all systems until we find what we're looking for
int iLoops = 20;
int iNodeIndex = 0;
int iSnapshotIndex = 0;
CTopologyNode *pNode = Universe.GetTopologyNode(iNodeIndex);
while (true)
{
// Create the system
CSystem *pSystem;
if (error = Universe.CreateStarSystem(pNode, &pSystem))
{
printf("ERROR: Unable to create star system.\n");
return;
}
// If this is the node we want, then search
CSpaceObject *pTarget;
if (sNode.IsBlank() || strEquals(sNode, pNode->GetID()))
{
printf("Searching %s...\n", pNode->GetSystemName().GetASCIIZPointer());
// Set the POV
CSpaceObject *pPOV = pSystem->GetObject(0);
Universe.SetPOV(pPOV);
pSystem->SetPOVLRS(pPOV);
// Prepare system
Universe.UpdateExtended();
Universe.GarbageCollectLibraryBitmaps();
// Update for a while
//.........这里部分代码省略.........
示例3: GenerateImageChart
//.........这里部分代码省略.........
int cxDesiredWidth;
if (pCmdLine->FindAttributeInteger(CONSTLIT("width"), &cxDesiredWidth))
cxDesiredWidth = Max(512, cxDesiredWidth);
else
cxDesiredWidth = 1280;
// Spacing
int cxSpacing = pCmdLine->GetAttributeInteger(CONSTLIT("xSpacing"));
int cxExtraMargin = pCmdLine->GetAttributeInteger(CONSTLIT("xMargin"));
int cxImageMargin = 2 * pCmdLine->GetAttributeInteger(CONSTLIT("xImageMargin"));
// Font for text
CString sTypeface;
int iSize;
bool bBold;
bool bItalic;
if (!CG16bitFont::ParseFontDesc(pCmdLine->GetAttribute(CONSTLIT("font")),
&sTypeface,
&iSize,
&bBold,
&bItalic))
{
sTypeface = CONSTLIT("Arial");
iSize = 10;
bBold = false;
bItalic = false;
}
CG16bitFont NameFont;
NameFont.Create(sTypeface, -PointsToPixels(iSize), bBold, bItalic);
CG32bitPixel rgbNameColor = CG32bitPixel(255, 255, 255);
// Rotation
int iRotation = pCmdLine->GetAttributeInteger(CONSTLIT("rotation"));
// Output file
CString sFilespec = pCmdLine->GetAttribute(CONSTLIT("output"));
if (!sFilespec.IsBlank())
sFilespec = pathAddExtensionIfNecessary(sFilespec, CONSTLIT(".bmp"));
// Generate a sorted table of types
TSortMap<CString, SEntryDesc> Table;
for (i = 0; i < Universe.GetDesignTypeCount(); i++)
{
CDesignType *pType = Universe.GetDesignType(i);
SEntryDesc NewEntry;
// Make sure we match the criteria
if (!pType->MatchesCriteria(Criteria))
continue;
// Figure stuff stuff out based on the specific design type
switch (pType->GetType())
{
case designItemType:
{
CItemType *pItemType = CItemType::AsType(pType);
示例4: InitStationTypeImage
//.........这里部分代码省略.........
// Loop over all satellites and get metrics
TArray<SSatImageDesc> SatImages;
for (i = 0; i < pSatellites->GetContentElementCount(); i++)
{
CXMLElement *pSatDesc = pSatellites->GetContentElement(i);
if (!pSatDesc->FindAttribute(SEGMENT_ATTRIB)
|| !strEquals(STATION_TAG, pSatDesc->GetTag()))
continue;
// Get the type of the satellite
CStationType *pSatType = g_pUniverse->FindStationType(pSatDesc->GetAttributeInteger(TYPE_ATTRIB));
if (pSatType == NULL)
continue;
// Prepare the image for the satellite
SSatImageDesc *pSatImage = SatImages.Insert();
pSatType->SetImageSelector(InitCtx, &pSatImage->Selector);
// If we have an image variant, then set it
int iVariant;
if (pSatDesc->FindAttributeInteger(IMAGE_VARIANT_ATTRIB, &iVariant))
{
IImageEntry *pRoot = pSatType->GetImage().GetRoot();
DWORD dwID = (pRoot ? pRoot->GetID() : DEFAULT_SELECTOR_ID);
pSatImage->Selector.DeleteAll();
pSatImage->Selector.AddVariant(dwID, iVariant);
}
pSatImage->pImage = &pSatType->GetImage(pSatImage->Selector, CCompositeImageModifiers());
// Now get the offset
pSatImage->xOffset = pSatDesc->GetAttributeInteger(X_OFFSET_ATTRIB);
pSatImage->yOffset = pSatDesc->GetAttributeInteger(Y_OFFSET_ATTRIB);
// Compute the satellite rect
RECT rcSatImage = pSatImage->pImage->GetImageRect();
RECT rcSatBounds;
rcSatBounds.left = pSatImage->xOffset - (RectWidth(rcSatImage) / 2);
rcSatBounds.top = -pSatImage->yOffset - (RectHeight(rcSatImage) / 2);
rcSatBounds.right = rcSatBounds.left + RectWidth(rcSatImage);
rcSatBounds.bottom = rcSatBounds.top + RectHeight(rcSatImage);
// Increase the size of the bounds
rcBounds.left = Min(rcBounds.left, rcSatBounds.left);
rcBounds.right = Max(rcBounds.right, rcSatBounds.right);
rcBounds.top = Min(rcBounds.top, rcSatBounds.top);
rcBounds.bottom = Max(rcBounds.bottom, rcSatBounds.bottom);
}
// If no segments, then we just return the basic image
if (SatImages.GetCount() == 0)
{
Entry.pImage = pMainImage;
return;
}
// Create an image that will hold the composite
CG32bitImage *pCompositeImage = new CG32bitImage;
pCompositeImage->Create(RectWidth(rcBounds), RectHeight(rcBounds), CG32bitImage::alpha8, CG32bitPixel::Null());
int xCenter = -rcBounds.left;
int yCenter = -rcBounds.top;
// Paint the main image
pMainImage->PaintImage(*pCompositeImage, xCenter, yCenter, 0, Entry.iRotation, true);
// Paint all the satellites
for (i = 0; i < SatImages.GetCount(); i++)
SatImages[i].pImage->PaintImage(*pCompositeImage, xCenter + SatImages[i].xOffset, yCenter - SatImages[i].yOffset, 0, 0, true);
// Now create the proper image array
RECT rcResult;
rcResult.left = 0;
rcResult.top = 0;
rcResult.right = RectWidth(rcBounds);
rcResult.bottom = RectHeight(rcBounds);
int xOffset = (RectWidth(rcBounds) / 2) - xCenter;
int yOffset = (RectHeight(rcBounds) / 2) - yCenter;
Entry.pCompositeImageArray = new CObjectImageArray;
Entry.pCompositeImageArray->Init(pCompositeImage, rcResult, 0, 0, true, xOffset, yOffset);
// Done
Entry.pImage = Entry.pCompositeImageArray;
}
示例5: TestPolygons
void TestPolygons (CUniverse &Universe, CXMLElement *pCmdLine)
{
int i;
const int FRAME_WIDTH = 256;
const int FRAME_HEIGHT = 256;
const int OUTPUT_WIDTH = FRAME_WIDTH * 2;
const int OUTPUT_HEIGHT = FRAME_HEIGHT;
// Options
int iCount = pCmdLine->GetAttributeInteger(CONSTLIT("count"));
if (iCount == 0)
iCount = 1000;
int iBltCount = Max(1, iCount / 10);
// Create the output image
CG32bitImage Output;
Output.Create(OUTPUT_WIDTH, OUTPUT_HEIGHT, CG32bitImage::alpha8);
// Create a regular polygon
const int iSides = 17;
const Metric rRadius = 100.0;
const Metric rAngleStep = (TAU / iSides);
TArray<CVector> Shape1;
Shape1.InsertEmpty(iSides);
for (i = 0; i < iSides; i++)
Shape1[i] = CVector::FromPolar(i * rAngleStep, rRadius);
// Create a point array, which we'll use for the binary region
SPoint Shape1Points[iSides];
for (i = 0; i < iSides; i++)
{
Shape1Points[i].x = (int)Shape1[i].GetX();
Shape1Points[i].y = (int)Shape1[i].GetY();
}
// Create a path
CGPath Shape1Path;
Shape1Path.Init(Shape1);
// We do timing tests first
TNumberSeries<Metric> Timing;
// Time rasterization of a binary region
const int CALLS_PER_SAMPLE = 1000;
const int BLTS_PER_SAMPLE = 100;
DWORD dwStart = ::GetTickCount();
for (i = 0; i < iCount; i++)
{
CG16bitBinaryRegion Region;
Region.CreateFromPolygon(iSides, Shape1Points);
if (((i + 1) % CALLS_PER_SAMPLE) == 0)
Timing.Insert((Metric)::sysGetTicksElapsed(dwStart, &dwStart));
}
printf("CG16bitBinaryRegion::CreateFromPolygon: %s ms per %d\n", (LPSTR)strFromDouble(Timing.GetMean()), CALLS_PER_SAMPLE);
// Time rasterization of path
Timing.DeleteAll();
dwStart = ::GetTickCount();
for (i = 0; i < iCount; i++)
{
CGRegion Region;
Shape1Path.Rasterize(&Region, 1);
if (((i + 1) % CALLS_PER_SAMPLE) == 0)
Timing.Insert((Metric)::sysGetTicksElapsed(dwStart, &dwStart));
}
printf("CGPath::Rasterize: %s ms per %d\n", (LPSTR)strFromDouble(Timing.GetMean()), CALLS_PER_SAMPLE);
// Create the regions
CG16bitBinaryRegion Shape1BinaryRegion;
Shape1BinaryRegion.CreateFromPolygon(iSides, Shape1Points);
CGRegion Shape1Region;
Shape1Path.Rasterize(&Shape1Region, 4);
// Time to blt
Timing.DeleteAll();
dwStart = ::GetTickCount();
for (i = 0; i < iBltCount; i++)
{
CGDraw::Region(Output, (FRAME_WIDTH / 2), (FRAME_HEIGHT / 2), Shape1BinaryRegion, CG32bitPixel(255, 255, 255));
if (((i + 1) % BLTS_PER_SAMPLE) == 0)
//.........这里部分代码省略.........
示例6: SetShipClassImage
void CNewGameSession::SetShipClassImage (CShipClass *pClass, int x, int y, int cxWidth)
// SetShipClassImage
//
// Sets the current ship class image
{
const CPlayerSettings *pPlayerSettings = pClass->GetPlayerSettings();
// Ask the class for a hero image
const CG32bitImage *pImage = (!pClass->GetHeroImage().IsEmpty() ? &pClass->GetHeroImage().GetImage(CONSTLIT("New Game")) : NULL);
// Delete the previous one
DeleteElement(ID_SHIP_CLASS_IMAGE);
// Add the new one, if we've got one.
const CG32bitImage *pImageToUse = NULL;
bool bFree = false;
if (pImage && !pImage->IsEmpty())
{
// If this image is not the right size, then create a resized version
// that is.
if (pImage->GetWidth() != SHIP_IMAGE_WIDTH || pImage->GetHeight() != SHIP_IMAGE_HEIGHT)
{
int cxNewWidth = SHIP_IMAGE_WIDTH;
int cyNewHeight = cxNewWidth * pImage->GetHeight() / pImage->GetWidth();
if (cyNewHeight > SHIP_IMAGE_HEIGHT)
{
cyNewHeight = SHIP_IMAGE_HEIGHT;
cxNewWidth = cyNewHeight * pImage->GetWidth() / pImage->GetHeight();
}
CG32bitImage *pNewImage = new CG32bitImage;
pNewImage->CreateFromImageTransformed(*pImage, 0, 0, pImage->GetWidth(), pImage->GetHeight(), (Metric)cxNewWidth / pImage->GetWidth(), (Metric)cyNewHeight / pImage->GetHeight(), 0.0);
pImageToUse = pNewImage;
bFree = true;
}
else
{
pImageToUse = pImage;
bFree = false;
}
}
// If we don't have an image then ask the class to paint it
else
{
CG32bitImage *pNewImage = new CG32bitImage;
pNewImage->Create(SHIP_IMAGE_WIDTH, SHIP_IMAGE_HEIGHT);
ViewportTransform Trans;
pClass->Paint(*pNewImage,
SHIP_IMAGE_WIDTH / 2,
SHIP_IMAGE_HEIGHT / 2,
Trans,
0,
0
);
pImageToUse = pNewImage;
bFree = true;
}
// Position
int xImage = x + (cxWidth - pImageToUse->GetWidth()) / 2;
int yImage = y + (SHIP_IMAGE_HEIGHT - pImageToUse->GetHeight()) / 2;
// New image frame
bool bAutoMask = (pClass->GetAPIVersion() < 26);
IAnimatron *pImageFrame = new CAniRect;
pImageFrame->SetID(ID_SHIP_CLASS_IMAGE);
pImageFrame->SetPropertyVector(PROP_POSITION, CVector(xImage, yImage));
pImageFrame->SetPropertyVector(PROP_SCALE, CVector(pImageToUse->GetWidth(), pImageToUse->GetHeight()));
pImageFrame->SetFillMethod(new CAniImageFill(pImageToUse, bFree, bAutoMask));
m_pRoot->AddLine(pImageFrame);
}
示例7: GetImage
void CFilterColorizeEntry::GetImage (const CCompositeImageSelector &Selector, CObjectImageArray *retImage)
// GetImage
//
// Fills in the image
{
// Null case
if (m_pSource == NULL)
{
*retImage = EMPTY_IMAGE;
return;
}
// Get the source image (which we want to colorize)
CObjectImageArray Source;
m_pSource->GetImage(Selector, &Source);
const RECT &rcSource = Source.GetImageRect();
CG32bitImage &SourceImage = Source.GetImage(NULL_STR);
int cxWidth = RectWidth(rcSource);
int cyHeight = RectHeight(rcSource);
if (!Source.IsLoaded() || cxWidth == 0 || cyHeight == 0)
{
*retImage = EMPTY_IMAGE;
return;
}
// Create the destination image
CG32bitImage *pDest = new CG32bitImage;
pDest->Create(cxWidth, cyHeight, SourceImage.GetAlphaType());
// Blt the to the destination with colorization
CGDraw::CopyColorize(*pDest,
0,
0,
SourceImage,
rcSource.left,
rcSource.top,
cxWidth,
cyHeight,
(REALPIXEL)m_dwHue,
(REALPIXEL)m_dwSaturation / 100.0);
// Initialize an image
RECT rcFinalRect;
rcFinalRect.left = 0;
rcFinalRect.top = 0;
rcFinalRect.right = cxWidth;
rcFinalRect.bottom = cyHeight;
CObjectImageArray Comp;
Comp.Init(pDest, rcFinalRect, 0, 0, true);
// Done
retImage->TakeHandoff(Comp);
}
示例8: CreateIcon
void CExtension::CreateIcon (int cxWidth, int cyHeight, CG32bitImage **retpIcon) const
// CreateIcon
//
// Creates a cover icon for the adventure. The caller is responsible for
// freeing the result.
{
// Load the image
CG32bitImage *pBackground = GetCoverImage();
if (pBackground == NULL || pBackground->GetWidth() == 0 || pBackground->GetHeight() == 0)
{
int cxSize = Min(cxWidth, cyHeight);
*retpIcon = new CG32bitImage;
(*retpIcon)->Create(cxSize, cxSize);
return;
}
// Figure out the dimensions of the icon based on the image size and the
// desired output.
//
// If the background is larger than the icon size then we need to scale it.
CG32bitImage *pIcon;
if (pBackground->GetWidth() > cxWidth || pBackground->GetHeight() > cyHeight)
{
int xSrc, ySrc, cxSrc, cySrc;
Metric rScale;
// If we have a widescreen cover image and we want a portrait or
// square icon, then we zoom in on the key part of the cover.
if (pBackground->GetWidth() > 2 * pBackground->GetHeight())
{
rScale = (Metric)cyHeight / pBackground->GetHeight();
cxSrc = (int)(cxWidth / rScale);
xSrc = Min(pBackground->GetWidth() - cxSrc, pBackground->GetWidth() - (RIGHT_COVER_OFFSET + (cxSrc / 2)));
ySrc = 0;
cySrc = pBackground->GetHeight();
}
else
{
rScale = (Metric)cxWidth / pBackground->GetWidth();
if (rScale * pBackground->GetHeight() > (Metric)cyHeight)
rScale = (Metric)cyHeight / pBackground->GetHeight();
xSrc = 0;
ySrc = 0;
cxSrc = pBackground->GetWidth();
cySrc = pBackground->GetHeight();
}
// Create the icon
pIcon = new CG32bitImage;
pIcon->CreateFromImageTransformed(*pBackground,
xSrc,
ySrc,
cxSrc,
cySrc,
rScale,
rScale,
0.0);
}
// Otherwise we center the image on the icon
else
{
// Create the icon
pIcon = new CG32bitImage;
pIcon->Create(cxWidth, cyHeight);
// Blt
pIcon->Blt(0,
0,
pBackground->GetWidth(),
pBackground->GetHeight(),
*pBackground,
(cxWidth - pBackground->GetWidth()) / 2,
(cyHeight - pBackground->GetHeight()) / 2);
}
// Done
*retpIcon = pIcon;
}