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


C++ Image::Allocate方法代码示例

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


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

示例1: main

int main(int argc, char* argv[]) {
	if (error(argc, argv)) return 1;
	char* index = argv[2];
	int oneSide = atoi(argv[4]);
	// this finds the length the binary number should be (number of pixels)
	int squareSize = pow(oneSide, 2); //==other calc log(size)/log(2) + 1;

	double size = pow(2, oneSide*oneSide) -1; // 511 is the max combinations for a 3x3 square of pixels
	// if (argv[1]==std::string("-percentage")) {
	// 	index = size*(index/100.0);
	// 	std::cout << index << std::endl;
	// }

	Image image;
	image.Allocate(oneSide);

	
	vector<vector<int> > coordinates(getCoordinates(squareSize));
	//only needed for all images solution
	// string binString[size];
	// for (int i = 0; i<size; i++) {
	// 	binString[i] = convertBin(squareSize, i);
	// }
	//cant use with large values (bigger than 10)
	// std::string aBin = convertBin(squareSize, index);
	// right now this only does one of the combinations for a size
	drawImage(image, coordinates, index);
	std::vector<unsigned char> png = image.getOutput();
	saveImage(index, png, oneSide);


	std::cout << "finished." << std::endl;
	return 0;
}
开发者ID:andykais,项目名称:PixProject,代码行数:34,代码来源:main.cpp

示例2: TakeScreenshot

		bool Renderer::TakeScreenshot(const char* directory_name)
		{
			// Fill our path string
			char filename[50];
			time_t now = time(nullptr);
			strftime(filename, _countof(filename), "SS.%Y.%m.%d.%H.%M.%S.jpg", localtime(&now));
			char delimeter[2] = { system::GetPathDelimeter(), '\0' };
			size_t size = strlen(directory_name) + strlen(filename) + 2; // 1 is for delimeter, another 1 is for \0
			char *full_filename = new char[size];
			strcpy(full_filename, directory_name);
			strcat(full_filename, delimeter);
			strcat(full_filename, filename);

			system::CreateDirectory(directory_name); // create directory if it doesn't exist

			Image image;
			// allocate memory and read pixels
			u8 *data = image.Allocate(width_, height_, Image::Format::kRGB8);
			ReadPixels(width_, height_, data);
			if (!image.Save(full_filename))
			{
				delete[] full_filename;
				return false;
			}

			delete[] full_filename;
			return true;
		}
开发者ID:Shtille,项目名称:ShtilleEngine,代码行数:28,代码来源:renderer.cpp

示例3: main

int main(int argc, char* argv[]) {
  if (argc != 5) {
    std::cerr << "Usage: " << argv[0] << " input.ppm output.ppm distance_field_method visualization_style" << std::endl;
    exit(1);
  }

  // open the input image
  Image<Color> input;
  if (!input.Load(argv[1])) {
    std::cerr << "ERROR: Cannot open input file: " << argv[1] << std::endl;
    exit(1);
  }

  // a place to write the distance values
  Image<DistancePixel> distance_image;
  distance_image.Allocate(input.Width(),input.Height());

  // calculate the distance field (each function returns the maximum distance value)
  double max_distance = 0;
  if (std::string(argv[3]) == std::string("naive_method")) {
    max_distance = NaiveDistanceFieldMethod(input,distance_image);
  } else if (std::string(argv[3]) == std::string("improved_method")) {
    max_distance = ImprovedDistanceFieldMethod(input,distance_image);
  } else if (std::string(argv[3]) == std::string("pq_with_map")) {
    max_distance = FastMarchingMethod(input,distance_image);
  } else if (std::string(argv[3]) == std::string("pq_with_hash_table")) {
    // EXTRA CREDIT: implement FastMarchingMethod with a hash table
  } else {
    std::cerr << "ERROR: Unknown distance field method: " << argv[3] << std::endl;
    exit(1);
  }

  // convert distance values to a visualization
  Image<Color> output;
  output.Allocate(input.Width(),input.Height());
  for (int i = 0; i < input.Width(); i++) {
    for (int j = 0; j < input.Height(); j++) {
      double v = distance_image.GetPixel(i,j).getValue();
      if (std::string(argv[4]) == std::string("greyscale")) {
	output.SetPixel(i,j,GreyBands(v,max_distance*1.01,1));
      } else if (std::string(argv[4]) == std::string("grey_bands")) {
	output.SetPixel(i,j,GreyBands(v,max_distance,4));
      } else if (std::string(argv[4]) == std::string("rainbow")) {
	output.SetPixel(i,j,Rainbow(v,max_distance));
      } else {
	// EXTRA CREDIT: create other visualizations 
	std::cerr << "ERROR: Unknown visualization style" << std::endl;
	exit(0);
      }
    }
  }
  // save output
  if (!output.Save(argv[2])) {
    std::cerr << "ERROR: Cannot save to output file: " << argv[2] << std::endl;
    exit(1);
  }

  return 0;
}
开发者ID:noeljt,项目名称:DataStructures,代码行数:59,代码来源:main.cpp


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