当前位置: 首页>>代码示例>>C++>>正文


C++ PNG::writeToFile方法代码示例

本文整理汇总了C++中PNG::writeToFile方法的典型用法代码示例。如果您正苦于以下问题:C++ PNG::writeToFile方法的具体用法?C++ PNG::writeToFile怎么用?C++ PNG::writeToFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PNG的用法示例。


在下文中一共展示了PNG::writeToFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main()
{ 
   SquareMaze m;
   m.makeMaze(TEST,TEST);
   std::cout << "MakeMaze complete" << std::endl;

    /*
    for ( int i = 0; i < TEST; i++)
    {
        for ( int j = 0; j < TEST ; j++)
        {
            cout <<"RIGHT: "<< m.canTravel(i,j,RIGHT)<< " x: "<<i<<" y: "<<j<<endl;
            cout <<"BOTTOM: "<< m.canTravel(i,j,BOTTOM)<< " x: "<<i<<" y: "<<j<<endl;
        }
    }
    */

   PNG* unsolved = m.drawMaze();
   unsolved->writeToFile("unsolved.png");
   delete unsolved;
   std::cout << "drawMaze complete" << std::endl;
   
   vector<int> sol = m.solveMaze();
   std::cout << "solveMaze complete" << std::endl;
   
   PNG* solved = m.drawMazeWithSolution();
   solved->writeToFile("solved.png");
   delete solved;
   std::cout << "drawMazeWithSolution complete" << std::endl;

   return 0;
}
开发者ID:AdonisSaveYourLife,项目名称:cs225,代码行数:32,代码来源:testsquaremaze.cpp

示例2: testWaterfall

void testWaterfall()
{
	cout << "[main]: " << __func__ << "()" << endl;
	PNG in("in_05.png");

	List<RGBAPixel> list = imageToList(in);
	list.waterfall();

	PNG out = listToImage(list, in.width(), in.height());
	out.writeToFile("waterfall_01.png");

	checkSoln(__func__, out, "soln_waterfall_01.png");

	in.readFromFile("in_06.png");
	list = imageToList(in);
	list.waterfall();
	out = listToImage(list, in.width(), in.height());
	out.writeToFile("waterfall_02.png");

	checkSoln(__func__, out, "soln_waterfall_02.png");
	
	List<int> list3;

	for (int i = 1; i <= 8; i++)
	list3.insertBack(i);
	list3.waterfall();
	//cout << "[waterfall custom]: " << list3 << endl;
}
开发者ID:guptadipanshu,项目名称:Data_structure,代码行数:28,代码来源:main.cpp

示例3: testReverseNth

void testReverseNth()
{
	cout << "[main]: " << __func__ << "()" << endl;
	PNG in("in_03.png");
	
    /*
    List<int> test;

    for (int i = 1; i <= 11; i++)
    {
        test.insertBack(i);
    }

    cout<<test<<endl;
    test.reverseNth(3);
    cout<<test<<endl;
    */
	List<RGBAPixel> list = imageToList(in);
	list.reverseNth(in.height() * 20);

	PNG out = listToImage(list, in.width(), in.height());
	out.writeToFile("reverseNth_01.png");

	checkSoln(__func__, out, "soln_reverseNth_01.png");

	in.readFromFile("in_04.png");
	list = imageToList(in);
	list.reverseNth(in.height() * 61);
	out = listToImage(list, in.width(), in.height());
	out.writeToFile("reverseNth_02.png");

	checkSoln(__func__, out, "soln_reverseNth_02.png");

}
开发者ID:AdonisSaveYourLife,项目名称:cs225,代码行数:34,代码来源:main.cpp

示例4: testWaterfall

void testWaterfall()
{
	List<double> li;
	cout<<li<<endl;
	li.waterfall();
	cout<<li<<endl;
	cout << "[main]: " << __func__ << "()" << endl;
	PNG in("in_05.png");

	List<RGBAPixel> list = imageToList(in);
	list.waterfall();

	PNG out = listToImage(list, in.width(), in.height());
	out.writeToFile("waterfall_01.png");

	checkSoln(__func__, out, "soln_waterfall_01.png");

	in.readFromFile("in_06.png");
	list = imageToList(in);
	list.waterfall();
	out = listToImage(list, in.width(), in.height());
	out.writeToFile("waterfall_02.png");

	checkSoln(__func__, out, "soln_waterfall_02.png");
}
开发者ID:Albertmt,项目名称:Data-Structures,代码行数:25,代码来源:main.cpp

示例5: main

/**
 * Simply parses the command line args and runs the appropriate functions.
 */
int main(int argc, char* argv[]){

    if(argc != 5)
    {
        cerr << endl;
        cerr << "Please run as " << argv[0] << " numThreads operation imageName saveFile" << endl;
        cerr << "    numThreads    number of threads to use (if #pragma omp... is encountered)" << endl;
        cerr << "    operation     \"flip\" or \"remove\"" << endl;
        cerr << "    imageName     for example, \"images/01_8182x4096.png\"" << endl;
        cerr << "    saveFile      \"yes\" (if you want to save output), \"no\" otherwise" << endl;
        cerr << endl;
        return 1;
    }

    // set the number of thread for the program to use (the first argument)
    omp_set_num_threads(atoi(argv[1]));
    
    // read the parameter PNG from file
    string filename(argv[3]);
    PNG img(filename);
    PNG output;

    cout << "Performing operation..." << endl;
    double start = omp_get_wtime();
    double end;
    if(argv[2][0] == 'f')
    {
        output = ImageTools::verticalFlip(img);
        end = omp_get_wtime();
        if(argv[4][0] == 'y')
        {
            cout << "Saving image..." << endl;
            output.writeToFile("flipped.png");
        }
    }
    else
    {
        Color color = GREEN;
        output = ImageTools::removeColor(img, color);
        end = omp_get_wtime();
        if(argv[4][0] == 'y')
        {
            cout << "Saving image..." << endl;
            output.writeToFile("removed.png");
        }
    }

    cout << "Total processed pixels: " << img.height() * img.width() << endl;
    cout << "Time: " << end - start << " seconds" << endl;
    return 0;
}
开发者ID:AdonisSaveYourLife,项目名称:cs225,代码行数:54,代码来源:main.cpp

示例6: pacmanTests

void pacmanTests() {
	cout << "Testing PacMan" << endl;

	// PAC MAN BFS
	PNG img;
	img.readFromFile("originals/pacMan.png");
	rainbowColorPicker BFSfiller(1.0/1000.0);
	animation pacManBFS = filler::bfs::fill(img, img.width()/2, img.height()/2,
	                               BFSfiller, 8000, INT_MAX);
	img.writeToFile("images/pacManBFS.png");
	cout << "\tWrote images/pacManBFS.png" << endl;
	//blueManBFS.write("pacManBFS.gif");

	// PAC MAN DFS
	img.readFromFile("originals/pacMan.png");
	rainbowColorPicker DFSfiller(1.0/1000.0);
	animation pacManDFS = filler::dfs::fill(img, img.width()/2, img.height()/2,
	                               DFSfiller, 8000, INT_MAX);
	img.writeToFile("images/pacManDFS.png");
	cout << "\tWrote images/pacManDFS.png" << endl;


	// Make ANTI image
	PNG antiImg;
	antiImg.readFromFile("originals/pacMan.png");
	RGBAPixel black;
	black.red = black.green = black.blue = 0;
	RGBAPixel grey;
	grey.red = grey.green = grey.blue = 1;
    filler::bfs::fillSolid(antiImg, 10, 10, grey, 8000, INT_MAX);
    filler::bfs::fillSolid(antiImg, antiImg.width()/2, antiImg.height()/2, black, 8000, INT_MAX);

	// ANTI PAC MAN BFS
	img = antiImg;
	rainbowColorPicker aBFSfiller(1.0/1000.0);
	animation aManBFS = filler::bfs::fill(img, 20, 20, aBFSfiller, 0, 2000);
	//img.writeToFile("antiPacManBFS.png");
	aManBFS.write("images/antiPacManBFS.gif");
	cout << "\tWrote images/antiPacManBFS.gif" << endl;

	// ANTI PAC MAN DFS
	img = antiImg;
	rainbowColorPicker aDFSfiller(1.0/1000.0);
	animation aManDFS = filler::dfs::fill(img, 20, 20, aDFSfiller, 0, 2000);
	//img.writeToFile("antiPacManDFS.png");
	aManDFS.write("images/antiPacManDFS.gif");
	cout << "\tWrote images/antiPacManDFS.gif" << endl;
}
开发者ID:Arkhtyi,项目名称:Discrete-structures,代码行数:48,代码来源:testFills.cpp

示例7: testFlip

/**
 * Tests the image flipping code.
 */
void testFlip()
{
    PNG image;
    cout << "Testing in-place image flipper:" << endl;
    image.readFromFile("images/03_2560x1680.png");

    cout << "  - flipping image" << endl;
    double startTime = omp_get_wtime();
    Flipper::flipParallel(image);
    double endTime = omp_get_wtime();
    double parallelTime = endTime - startTime;

    cout << "  - saving image" << endl;
    image.writeToFile("flipped.png");
    cout << "Elapsed flip time: " << parallelTime << endl;

    cout << "Checking correctness: ";
    bool correct = Flipper::checkCorrectness(image);
    cout << (correct ? makeGreen("PASS") : makeRed("FAIL") + " (the images are different)") << endl;

    startTime = omp_get_wtime();
    Flipper::flipSerial(image);
    endTime = omp_get_wtime();
    cout << "Speedup: " << (endTime - startTime) / parallelTime << endl;
}
开发者ID:chrislee0793,项目名称:CS225,代码行数:28,代码来源:main.cpp

示例8: main

int main()
{
	PNG oldImage;
	oldImage.readFromFile("in.png");	
	size_t vertical = oldImage.height();
	size_t horizontal = oldImage.width();
/*
* have initialized newImage just so that the pixels are accessable 
*/
	PNG newImage;
	newImage.readFromFile("in.png");
/*
 * we will flip the image horizontally and vertically to rotate it by 180 degrees
*/
	for (size_t x = 0; x < oldImage.width(); x++)
	{	
		for (size_t y = 0; y < oldImage.height(); y++)
		{
			newImage(horizontal-x-1, vertical-y-1)->red = oldImage(x,y)->red;
			newImage(horizontal-x-1, vertical-y-1)->green = oldImage(x,y)->green;
			newImage(horizontal-x-1, vertical-y-1)->blue = oldImage(x,y)->blue;
		}
	}
	newImage.writeToFile("out.png");
}	
开发者ID:dwatring,项目名称:Data-Structures,代码行数:25,代码来源:main.cpp

示例9: testCollage

/**
 * Tests the collage code with the appropriate algorithm.
 */
void testCollage(DrawAlgorithm algorithm)
{
    cout << "Testing collage:" << endl;
    vector<PNG> layers = setupImages();
    vector<Point> coords = setupPoints();
    Collage collage(layers, coords);

    double startTime = omp_get_wtime();
    PNG* result = collage.draw(algorithm, true);
    double endTime = omp_get_wtime();
    double parallelTime = endTime - startTime;

    cout << "  - saving image" << endl;
    result->writeToFile("collage.png");    
    cout << "Elapsed collage time: " << parallelTime << endl;

    cout << "Checking correctness: ";
    bool correct = collage.checkCorrectness(*result);
    cout << (correct ? makeGreen("PASS") : makeRed("FAIL") + " (the images are different)") << endl;
    delete result;

    startTime = omp_get_wtime();
    result = collage.draw(algorithm, false);
    endTime = omp_get_wtime();
    cout << "Speedup: " << (endTime - startTime) / parallelTime << endl;
    delete result;
}
开发者ID:chrislee0793,项目名称:CS225,代码行数:30,代码来源:main.cpp

示例10: makePhotoMosaic

void makePhotoMosaic(const string & inFile, const string & tileDir, int numTiles, int pixelsPerTile, const string & outFile)
{
	PNG inImage(inFile);
	SourceImage source(inImage, numTiles);
	vector<TileImage> tiles = getTiles(tileDir);

	if (tiles.empty())
	{
		cerr << "ERROR: No tile images found in " << tileDir << endl;
		exit(2);
	}

	MosaicCanvas::enableOutput = true;
	MosaicCanvas * mosaic = mapTiles(source, tiles);
	cerr << endl;

	if (mosaic == NULL)
	{
		cerr << "ERROR: Mosaic generation failed" << endl;
		exit(3);
	}

	PNG result = mosaic->drawMosaic(pixelsPerTile);
	cerr << "Saving Output Image... ";
	result.writeToFile(outFile);
	cerr << "Done" << endl;
	delete mosaic;
}
开发者ID:irtefa,项目名称:dumbshit,代码行数:28,代码来源:photomosaic.cpp

示例11: main

int main(int argc, char* argv[])
{
	const int canvas_width = 128;
	const int canvas_height = 128;

	PNG canvas;
	canvas.resize(canvas_width, canvas_height);


	const RGBAPixel triangle_color = color::ORANGE;
	Shape* triangle = new Triangle(triangle_color,
			Vector2(32, 32),
			Vector2(64, 64),
			Vector2(32, 64));

	triangle->draw(&canvas);

	canvas.writeToFile("test_destructor.png");

	/* TODO: Why is this leaking memory?  Triangle does have a valid destructor!?
	 * Can you stop it from leaking WITHOUT changing triangle's type from a
	 * Shape pointer to a Triangle pointer type? */
	delete triangle;
	triangle = NULL;

	return 0;
}
开发者ID:irtefa,项目名称:dumbshit,代码行数:27,代码来源:test_destructor.cpp

示例12: main

int main()
{

	// Load in.png
	PNG * original;

	original=new PNG;
	original->readFromFile("in.png");
	int width  = original->width();
	int height = original->height();
	// Create out.png
	PNG * output;
	output = new PNG;
	output = setupOutput(width, height);	
	// Loud our favorite color to color the outline
	RGBAPixel * myPixel;
	myPixel=new RGBAPixel;
	myPixel= myFavoriteColor(192);

	

	// Go over the whole image, and if a pixel differs from that to its upper
	// left, color it my favorite color in the output
	for (int y = 1; y < height; y++)
	{
		for (int x = 1; x < width; x++)
		{
			// Calculate the pixel difference
			RGBAPixel * prev = (*original)(x-1, y-1);
			RGBAPixel * curr = (*original)(x  , y  );
			int diff = abs(curr->red   - prev->red  ) +
					   abs(curr->green - prev->green) +
					   abs(curr->blue  - prev->blue );

			// If the pixel is an edge pixel,
			// color the output pixel with my favorite color
			RGBAPixel * currOutPixel = (*output)(x,y);
			if (diff > 100)
				{currOutPixel->red=myPixel->red;
currOutPixel->green=myPixel->green;
currOutPixel->blue=myPixel->blue;}

		
	}
}

	// Save the output file
	output->writeToFile("out.png");


	// Clean up memory
	myPixel=NULL;
	delete myPixel;
	delete output;
	output=NULL;
	delete original;
	original=NULL;
	return 0;
}
开发者ID:cwang100,项目名称:class-projects,代码行数:59,代码来源:main.cpp

示例13: main

int main(int argc, char* argv[])
{
	const int canvas_width = 128;
	const int canvas_height = 128;

	PNG canvas;
	canvas.resize(canvas_width, canvas_height);

	Vector2 rectangle_center(canvas_width / 2, canvas_height / 2);
	const int rectangle_width = canvas_width / 4;
	const int rectangle_height = canvas_height / 4;
	Rectangle* rectangle = new Rectangle(rectangle_center,
			color::BLUE,
			rectangle_width,
			rectangle_height);

	rectangle->draw(&canvas);

	const int rectangle_perimeter = rectangle->perimeter();
	cout << "Rectangle's Perimeter = " << rectangle_perimeter << endl;
	const int rectangle_area = rectangle->area();
	cout << "Rectangle's Area = " << rectangle_area << endl;

	/* But we can treat a Rectangle just like a Shape using a Shape pointer */
	Shape* shape = rectangle;
	const int shape_perimeter = shape->perimeter();
	cout << "Shape's Perimeter = " << shape_perimeter << endl;
	const int shape_area = shape->area();
	cout << "Shape' Area = " << shape_area << endl;

	/* TODO: For some reason the shape's area and perimeter is different from
	 * triangle's area and perimeter even though they are pointing to the same
	 * object!  Can you this this so they are the same WITHOUT changing the
	 * shape's type from a Shape pointer to a Triangle pointer? */
	if (rectangle_perimeter == shape_perimeter)
	{
		cout << "The Perimeters are the same!" << endl;
	} else
	{
		
		cout << "The Perimeters are NOT the same." << endl;
	}

	if (rectangle_area == shape_area)
	{
		cout << "The Areas are the same!" << endl;
	} else
	{
		cout << "The Areas are NOT the same." << endl;
	}

	canvas.writeToFile("test_virtual.png");

	delete rectangle;

	return 0;
}
开发者ID:guptadipanshu,项目名称:Data_structure,代码行数:57,代码来源:test_virtual.cpp

示例14: sketchify

void sketchify()
{
	// Load in.png
	PNG * original;

	//std::cout << "Reached line 28" << endl;	
	original = new PNG();
	original->readFromFile("in.png");
	int width  = original->width();
	int height = original->height();
	//std::cout << "Reached line 32" << endl;

	// Create out.png
	PNG * output = setupOutput(width, height);	

	// Loud our favorite color to color the outline
	RGBAPixel * myPixel = myFavoriteColor(192);

	// Go over the whole image, and if a pixel differs from that to its upper
	// left, color it my favorite color in the output
	for (int y = 1; y < height; y++)
	{
		//std::cout << "begin" << endl;
		for (int x = 1; x < width; x++)
		{
			// Calculate the pixel difference
			RGBAPixel * prev = (*original)(x-1, y-1);
			RGBAPixel * curr = (*original)(x  , y  );
			int diff = abs(curr->red   - prev->red  ) +
					   abs(curr->green - prev->green) +
					   abs(curr->blue  - prev->blue );

			// If the pixel is an edge pixel,
			// color the output pixel with my favorite color
			RGBAPixel * currOutPixel =(*output)(x,y);

			if (diff > 100)
				*currOutPixel = *myPixel;
				//*(*output)(x,y) = *myPixel;
			
		}
		//std::cout << "end" << endl;
	}
	
	// Save the output file
	//std::cout << "begin" << endl;
	output->writeToFile("out.png");
	//std::cout << "end" << endl;

	// Clean up memory
	delete myPixel;
	//std::cout << "check1" << endl;
	delete output;
	delete original;
	//std::cout << "check2" << endl;
}
开发者ID:Yankkk,项目名称:C-,代码行数:56,代码来源:sketchify.cpp

示例15: main

int main()
{
   SquareMaze m;
   m.makeMaze(2, 2);
   std::cout << "MakeMaze complete" << std::endl;

   PNG* unsolved = m.drawMaze();
   unsolved->writeToFile("unsolved.png");
   delete unsolved;
   std::cout << "drawMaze complete" << std::endl;
   
   vector<int> sol = m.solveMaze();
   std::cout << "solveMaze complete" << std::endl;

   PNG* solved = m.drawMazeWithSolution();
   solved->writeToFile("solved.png");
   delete solved;
   std::cout << "drawMazeWithSolution complete" << std::endl;

   return 0;
}
开发者ID:killbug2004,项目名称:Snippets,代码行数:21,代码来源:testsquaremaze.cpp


注:本文中的PNG::writeToFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。