本文整理汇总了C++中GImage类的典型用法代码示例。如果您正苦于以下问题:C++ GImage类的具体用法?C++ GImage怎么用?C++ GImage使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GImage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: silhouetteCount
void silhouetteCount(string nameImageFile){
int silhouetteCounter=0;
GImage* imageFile = new GImage(nameImageFile);
GBufferedImage* imgageInBuffer = new GBufferedImage(0,0,imageFile->getWidth(), imageFile->getHeight());
imgageInBuffer->load(nameImageFile);
int imgHaight = imgageInBuffer->getHeight();
int imgWidth = imgageInBuffer->getWidth();
GWindow gw(imgWidth, imgHaight);
gw.add(imageFile);
myGrid imageBinaring(imgHaight, imgWidth);
binaringImageToGrid(imgageInBuffer, imageBinaring);
bool silhouetteIsValid = false;
for(int x = 0; x < imgHaight; x++){
for (int y = 0; y < imgWidth; y++){
if (imageBinaring.get_color(x,y) == true && imageBinaring.get_visited(x,y) == false) {
selectFindeArea(x,y, imageBinaring, silhouetteIsValid);
if (silhouetteIsValid) silhouetteCounter++;
}
}
}
cout<<"in File: "<<nameImageFile<<"; found "<< silhouetteCounter<<" silhouettes."<<endl;
cout<<endl;
delete imgageInBuffer;
delete imageFile;
}
开发者ID:shpp-nbezai,项目名称:cs-b-Assignment2-silhouetteCount,代码行数:32,代码来源:cs-b-Assignment2-silhouetteCount.cpp
示例2: HelloDialog
HelloDialog(HelloController* pController, int w, int h)
: GWidgetDialog(w, h, 0xff90d0f0) // a=ff, r=90, g=d0, b=f0
{
m_pController = pController;
m_pImage = new GImage();
m_pImage->setSize(800, 600);
m_pCanvas = new GWidgetCanvas(this, 10, 30, m_pImage->width(), m_pImage->height(), m_pImage);
m_pQuitButton = new GWidgetTextButton(this, 850, 300, 80, 24, "Quit");
}
示例3: finder
// static
void GSubImageFinder2::test()
{
// Make some random image
GImage foo;
foo.setSize(256, 256);
foo.clear(0xff000000);
foo.boxFill(13, 8, 12, 17, 0xff808030);
foo.boxFill(8, 13, 10, 9, 0xff407040);
foo.boxFill(20, 20, 220, 220, 0xffffffee);
// Make the finder
GSubImageFinder2 finder(&foo);
// Make a sub-image
GRect r2(0, 0, 256, 256);
GRect r;
r.x = 13;
r.y = 17;
r.w = 32;
r.h = 32;
GImage bar;
bar.setSize(32, 32);
bar.blit(0, 0, &foo, &r);
// Find the sub-image
r.x = 0;
r.y = 0;
int x, y;
finder.findSubImage(&x, &y, &bar, &r);
if(x != 13 || y != 17)
throw "wrong answer";
}
示例4: PopupView
PopupView(GWidgetDialog* pDialog)
: ViewBase()
{
m_nLeft = 0;
m_nTop = 0;
m_pBackgroundImage = new GImage();
captureScreen(m_pBackgroundImage);
m_pBackgroundImage->contrastAndBrightness(.5, -64);
m_pDialog = pDialog;
m_x = (m_pBackgroundImage->width() - m_pDialog->rect()->w) / 2;
m_y = (m_pBackgroundImage->height() - m_pDialog->rect()->h) / 2;
}
示例5: switch
void Image4uint8::copyGImage(const GImage& im) {
switch (im.channels()) {
case 1:
copyArray(im.pixel1(), im.width(), im.height());
break;
case 3:
copyArray(im.pixel3(), im.width(), im.height());
break;
case 4:
copyArray(im.pixel4(), im.width(), im.height());
break;
}
}
示例6: test_image
void test_image() {
GImage *im = new GImage("avatar.gif"); // in images subdirectory
GImage *webIm = new GImage("http://tikiloungetalk.com/wp-content/uploads/2010/11/speedracer-old.jpg");
#ifdef _WIN32
GImage *absPathIm = new GImage("C:/Qt/Qt5.3.2/Tools/QtCreator/share/qtcreator/qmlicons/Qt/16x16/CountBubble.png");
#else
GImage *absPathIm = new GImage("/usr/share/doc/cups/images/smiley.jpg");
#endif
gw->add(im, 10, 10);
int x = 10 + im->getWidth();
gw->add(webIm, x, 10);
x += webIm->getWidth();
gw->add(absPathIm, x, 10);
}
示例7: stringLabel
// static
void GPlotWindow::stringLabel(GImage* pImage, const char* szText, int x, int y, float size, unsigned int color, double angle)
{
// Draw the label such that it ends at the center of the temp image
int width = GImage::measureTextWidth(szText, size);
int nSize = (int)(std::max((float)width, size * 12) * 2.3);
GImage tmp;
tmp.setSize(nSize, nSize);
tmp.clear(0x0);
tmp.text(szText, nSize / 2 - width, (int)((nSize - size * 12) / 2), size, color, 1000, 1000);
// Rotate the label around the center
GImage tmp2;
tmp2.rotate(&tmp, nSize / 2, nSize / 2, angle);
// Blit such that the label ends at the specified point
GRect r(0, 0, nSize, nSize);
pImage->blitAlpha(x - nSize / 2, y - nSize / 2, &tmp2, &r);
}
示例8: GetCaptchaText
void ViewNewAccount::MakeCaptcha(const char* szID, ostream& response)
{
char szText[32];
GetCaptchaText(szText, szID);
std::ostringstream& r = reinterpret_cast<std::ostringstream&>(response);
r.str("");
r.clear();
// Make the filename
char szTemp[512];
GFile::tempFilename(szTemp);
// Make the captcha
GImage image;
image.captcha(szText, m_pServer->prng());
image.savePng(szTemp);
m_pServer->sendFile("image/png", szTemp, response);
DeleteFile(szTemp);
}
示例9: regionMask
void G2DRegionGraph::makeWatershedRegions(const GImage* pImage)
{
GImage gradMag;
gradMag.gradientMagnitudeImage(pImage);
GImage* pMask = regionMask();
int x, y, u, v, du, dv;
size_t region, other;
for(y = 0; y < (int)pImage->height(); y++)
{
for(x = 0; x < (int)pImage->width(); x++)
{
u = x;
v = y;
do
{
region = pMask->pixel(u, v);
if(region != 0xffffffff)
break;
PickTobogganDirection(&gradMag, u, v, &du, &dv);
u += du;
v += dv;
} while(du != 0 || dv != 0);
if(region == 0xffffffff)
{
region = addRegion();
setMaskPixel(u, v, pImage->pixel(u, v), region);
}
u = x;
v = y;
do
{
if(pMask->pixel(u, v) != 0xffffffff)
break;
setMaskPixel(u, v, pImage->pixel(u, v), region);
PickTobogganDirection(&gradMag, u, v, &du, &dv);
u += du;
v += dv;
} while(du != 0 || dv != 0);
if(x > 0)
{
other = pMask->pixel(x - 1, y);
if(other != region)
makeNeighbors(region, other);
}
if(y > 0)
{
other = pMask->pixel(x, y - 1);
if(other != region)
makeNeighbors(region, other);
}
}
}
}
示例10: makeMove
bool MarbleGraphics::makeMove(const Move move){
GImage * movingMarble = marbles[move.startRow][move.startCol];
int jumpedRow = move.startRow+(move.endRow-move.startRow)/2;
int jumpedCol = move.startCol+(move.endCol-move.startCol)/2;
GImage * jumpedMarble = marbles[jumpedRow][jumpedCol];
if (movingMarble == NULL || jumpedMarble == NULL){
return false;
}
//Move empty spot from end to start of move
GOval* endSpot = spaces[move.endRow][move.endCol];
double tempX = endSpot->getX();
double tempY = endSpot->getY();
endSpot->setLocation(movingMarble->getX(), movingMarble->getY());
spaces[move.startRow][move.startCol] = endSpot;
spaces[move.endRow][move.endCol] = NULL;
spaceCoords[endSpot] = Coord(move.startRow, move.startCol);
//Move image at start location to image at end location
movingMarble->setLocation(tempX, tempY);
marbles[move.endRow][move.endCol] = movingMarble;
marbles[move.startRow][move.startCol] = NULL;
marbleCoords[movingMarble] = Coord(move.endRow, move.endCol);
//Delete marble for jumped space and create empty space there instead
marbles[jumpedRow][jumpedCol] = NULL;
marbleCoords.remove(jumpedMarble);
remove(jumpedMarble);
delete jumpedMarble;
GOval* jumpedSpace = new GOval(kMarbleDimension, kMarbleDimension);
spaces[jumpedRow][jumpedCol] = jumpedSpace;
spaceCoords[jumpedSpace] = Coord(jumpedRow, jumpedCol);
add(jumpedSpace, jumpedCol*(kMarbleDimension+kMarbleSpacingWidth)+kMarbleSpacingWidth,
jumpedRow*(kMarbleDimension+kMarbleSpacingWidth)+kMarbleSpacingWidth);
return true;
}
示例11: CarOnHillModel
CarOnHillModel(GRand* prng, GImage* pImage, GWidgetTextLabel* pWins)
{
m_pWins = pWins;
m_wins = 0;
m_pImage = pImage;
m_carPos = 0;
m_velocity = 0;
m_prng = prng;
// Load the car image and add some border so we can rotate it
GImage tmp;
tmp.loadPng("minicar.png");
m_pCar = new GImage();
m_pCar->setSize(70, 60);
GRect r(0, 0, 60, 36);
m_pCar->blit(5, 5, &tmp, &r);
m_pRotatedCar = new GImage();
// Make the agent
GMixedRelation* pRelAgent = new GMixedRelation();
sp_relation relAgent;
relAgent = pRelAgent;
pRelAgent->addAttr(0); // position
pRelAgent->addAttr(0); // velocity
pRelAgent->addAttr(2); // action {forward, reverse}
double initialState[2];
initialState[0] = m_carPos;
initialState[1] = m_velocity;
double goalState[2];
goalState[0] = 2;
goalState[1] = 0;
m_pActionIterator = new GDiscreteActionIterator(2);
m_pAgents[0] = new CarQAgent(relAgent, initialState, m_prng, m_pActionIterator);
((GQLearner*)m_pAgents[0])->setLearningRate(.9);
((GQLearner*)m_pAgents[0])->setDiscountFactor(0.999);
}
示例12: CarOnHillDialog
CarOnHillDialog(CarOnHillController* pController, int w, int h)
: GWidgetDialog(w, h, 0xff90d0f0)
{
m_pController = pController;
m_pBullets = new GWidgetBulletGroup(this, 820, 102, 14, 14, 2, 30, true);
new GWidgetTextLabel(this, 840, 100, 100, 24, "Mouse", 0xff306000);
new GWidgetTextLabel(this, 840, 130, 100, 24, "Q-Learner", 0xff306000);
m_pBullets->setSelection(1);
m_pWins = new GWidgetTextLabel(this, 820, 300, 100, 24, "Wins: 0", 0xff306000, 0xff90d0f0);
m_pUpdateDisplay = new GWidgetCheckBox(this, 820, 402, 18, 18);
m_pUpdateDisplay->setChecked(true);
new GWidgetTextLabel(this, 840, 400, 100, 24, "Slow", 0xff306000);
m_pImage = new GImage();
m_pImage->setSize(800, 600);
m_pCanvas = new GWidgetCanvas(this, 10, 30, m_pImage->width(), m_pImage->height(), m_pImage);
m_prng = new GRand(0);
m_pModel = new CarOnHillModel(m_prng, m_pImage, m_pWins);
m_bPrevUpdate = true;
}
示例13: setIcon
void SDLWindow::setIcon(const GImage& image) {
alwaysAssertM((image.channels == 3) ||
(image.channels == 4),
"Icon image must have at least 3 channels.");
#ifdef G3D_WIN32
alwaysAssertM((image.width == 32) && (image.height == 32),
"Icons must be 32x32 on windows.");
#endif
uint32 amask = 0xFF000000;
uint32 bmask = 0x00FF0000;
uint32 gmask = 0x0000FF00;
uint32 rmask = 0x000000FF;
if (image.channels == 3) {
// Take away the 4th channel.
amask = 0x00000000;
}
int pixelBitLen = image.channels * 8;
int scanLineByteLen = image.channels * image.width;
SDL_Surface* surface =
SDL_CreateRGBSurfaceFrom((void*)image.byte(), image.width, image.height,
pixelBitLen, scanLineByteLen,
rmask, gmask, bmask, amask);
alwaysAssertM((surface != NULL),
"Icon data failed to load into SDL.");
// Let SDL create mask from image data directly
SDL_WM_SetIcon(surface, NULL);
SDL_FreeSurface(surface);
}
示例14: defined
SDLWindow::SDLWindow(const GWindow::Settings& settings) {
#if defined(G3D_OSX)
NSApplicationWrapper wrapper;
// Hack to get our window/process to the front...
ProcessSerialNumber psn = { 0, kCurrentProcess};
TransformProcessType (&psn, kProcessTransformToForegroundApplication);
SetFrontProcess (&psn);
_pool = new NSAutoreleasePoolWrapper();
#endif
if (SDL_Init(SDL_INIT_NOPARACHUTE | SDL_INIT_VIDEO |
SDL_INIT_JOYSTICK) < 0 ) {
fprintf(stderr, "Unable to initialize SDL: %s\n", SDL_GetError());
debugPrintf("Unable to initialize SDL: %s\n", SDL_GetError());
Log::common()->printf("Unable to initialize SDL: %s\n", SDL_GetError());
exit(1);
}
// Set default icon if available
if (settings.defaultIconFilename != "nodefault") {
try {
GImage defaultIcon;
defaultIcon.load(settings.defaultIconFilename);
setIcon(defaultIcon);
} catch (const GImage::Error& e) {
// Throw away default icon
fprintf(stderr, "GWindow's default icon failed to load: %s (%s)", e.filename.c_str(), e.reason.c_str());
debugPrintf("GWindow's default icon failed to load: %s (%s)", e.filename.c_str(), e.reason.c_str());
Log::common()->printf("GWindow's default icon failed to load: %s (%s)", e.filename.c_str(), e.reason.c_str());
}
}
if (! settings.fullScreen) {
// This doesn't really work very well due to SDL bugs so we fix up
// the position after the window is created.
if (settings.center) {
System::setEnv("SDL_VIDEO_CENTERED", "");
} else {
System::setEnv("SDL_VIDEO_WINDOW_POS", format("%d,%d", settings.x, settings.y));
}
}
_mouseVisible = true;
_inputCapture = false;
// Request various OpenGL parameters
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, settings.depthBits);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, settings.stencilBits);
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, settings.rgbBits);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, settings.rgbBits);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, settings.rgbBits);
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, settings.alphaBits);
SDL_GL_SetAttribute(SDL_GL_STEREO, settings.stereo);
#if SDL_FSAA
if (settings.fsaaSamples > 1) {
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES,
settings.fsaaSamples);
}
#endif
// Create a width x height OpenGL screen
int flags =
SDL_HWSURFACE |
SDL_OPENGL |
(settings.fullScreen ? SDL_FULLSCREEN : 0) |
(settings.resizable ? SDL_RESIZABLE : 0) |
(settings.framed ? 0 : SDL_NOFRAME);
if (SDL_SetVideoMode(settings.width, settings.height, 0, flags) == NULL) {
debugAssert(false);
Log::common()->printf("Unable to create OpenGL screen: %s\n",
SDL_GetError());
error("Critical Error",
format("Unable to create OpenGL screen: %s\n",
SDL_GetError()).c_str(), true);
SDL_Quit();
exit(2);
}
// See what video mode we really got
_settings = settings;
int depthBits, stencilBits, redBits, greenBits, blueBits, alphaBits;
glGetIntegerv(GL_DEPTH_BITS, &depthBits);
glGetIntegerv(GL_STENCIL_BITS, &stencilBits);
glGetIntegerv(GL_RED_BITS, &redBits);
glGetIntegerv(GL_GREEN_BITS, &greenBits);
glGetIntegerv(GL_BLUE_BITS, &blueBits);
glGetIntegerv(GL_ALPHA_BITS, &alphaBits);
int actualFSAABuffers = 0, actualFSAASamples = 0;
//.........这里部分代码省略.........
示例15: draw
virtual void draw(SDL_Surface *pScreen)
{
GImage* pDialogImage = m_pDialog->image();
m_pBackgroundImage->blit(m_x, m_y, pDialogImage, m_pDialog->rect());
blitImage(pScreen, m_nLeft, m_nTop, m_pBackgroundImage);
}