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


C++ RefPtr::write_to_png方法代码示例

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


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

示例1: renderLabels

	void renderLabels(const char* path)
	{
		BOOST_TEST_MESSAGE("Render: " << path);

		Cairo::RefPtr<Cairo::Surface> surface = Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32,
			META_TILE_SIZE * TILE_SIZE, META_TILE_SIZE * TILE_SIZE);
		Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create(surface);
		cr->set_source_rgba(0.0, 0.0, 0.0, 1.0);

		cr->save();
		cr->set_source_rgba(1.0, 1.0, 1.0, 1.0);
		cr->paint();
		cr->restore();

		std::vector<std::pair<string, FloatPoint>> toPlace;
		toPlace.push_back(std::pair<string, FloatPoint>("Karlsruhe", FloatPoint(40, 200)));
		toPlace.push_back(std::pair<string, FloatPoint>("Mannheim", FloatPoint(400, 200)));
		toPlace.push_back(std::pair<string, FloatPoint>("Stuttgard", FloatPoint(200, 260)));
		toPlace.push_back(std::pair<string, FloatPoint>("München", FloatPoint(380, 660)));
		toPlace.push_back(std::pair<string, FloatPoint>("Pforzheim", FloatPoint(200, 600)));
		toPlace.push_back(std::pair<string, FloatPoint>("Wien", FloatPoint(240, 680)));
		toPlace.push_back(std::pair<string, FloatPoint>("Paris", FloatPoint(40, 880)));
		toPlace.push_back(std::pair<string, FloatPoint>("Rom", FloatPoint(-40, 880)));
		toPlace.push_back(std::pair<string, FloatPoint>("Nothing", FloatPoint(400, 760)));
		toPlace.push_back(std::pair<string, FloatPoint>("To See", FloatPoint(720, 880)));
		toPlace.push_back(std::pair<string, FloatPoint>("Here", FloatPoint(720, 560)));
		toPlace.push_back(std::pair<string, FloatPoint>("Bielefeld", FloatPoint(420, 840)));
		renderer->renderLabels(cr, toPlace);

		BOOST_TEST_MESSAGE("Writing.");
		surface->flush();
		surface->write_to_png(path);
	}
开发者ID:Komzpa,项目名称:alacarte,代码行数:33,代码来源:placement_test.cpp

示例2: make_image

void make_image(Glib::ustring filename, void (shape_function)( Papyrus::Canvas::pointer ) ) {
  Cairo::RefPtr<Cairo::ImageSurface> surface =
      Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, 200, 200);

  Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create(surface);

  Papyrus::Canvas::pointer canvas = Papyrus::Canvas::create();
  canvas->translate( 100, 100 );
//   canvas->set_background( Cairo::SolidPattern::create_rgb(0.9, 0.9, 0.9) );
  Papyrus::Polyline::pointer line = Papyrus::Polyline::create();
  line->add_vertex(0, -100);
  line->add_vertex(0, 100);
  line->set_stroke( Cairo::SolidPattern::create_rgb(0.0, 0.0, 1.0) );
  line->stroke()->set_width(2);
  canvas->add( line );
  line = Papyrus::Polyline::create();
  line->add_vertex(-100, 0);
  line->add_vertex(100, 0);
  line->set_stroke( Cairo::SolidPattern::create_rgb(0.0, 0.0, 1.0) );
  line->stroke()->set_width(2);
  canvas->add( line );
  shape_function( canvas );

  canvas->render( cr );

  surface->write_to_png(filename);

  std::cout << "Wrote png file \"" << filename << "\"" << std::endl;

}
开发者ID:scott--,项目名称:papyrus,代码行数:30,代码来源:shapes.cpp

示例3: main

int main(int, char**) {
	Cairo::RefPtr<Cairo::ImageSurface> surface = Cairo::ImageSurface::create(
			Cairo::FORMAT_ARGB32, WIDTH, HEIGHT);
	Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create(surface);
	// fill background in white
	cr->set_source_rgb(1.0, 1.0, 1.0);
	cr->paint();

	// draw a little dot at the point where text will be drawn
	cr->arc(TEXT_ORIGIN_X, TEXT_ORIGIN_Y, FONT_SIZE / 4.0, 0, 2 * M_PI);
	cr->set_source_rgba(0.0, 1.0, 0.0, 0.5);
	cr->fill();

	// draw the text
	cr->move_to(TEXT_ORIGIN_X, TEXT_ORIGIN_Y);
	cr->set_source_rgb(0.8, 0.2, 0.2);
	Cairo::RefPtr<Cairo::ToyFontFace> font = Cairo::ToyFontFace::create(
			"Bitstream Charter", Cairo::FONT_SLANT_ITALIC,
			Cairo::FONT_WEIGHT_BOLD);
	cr->set_font_face(font);
	cr->set_font_size(FONT_SIZE);
	cr->show_text("cairomm!");
	surface->write_to_png("toy-text.png");
	return 0;
}
开发者ID:hamedobaidy,项目名称:cairomm_examples,代码行数:25,代码来源:toy_text.cpp

示例4: SavePng

void ImageWidget::SavePng(const std::string &filename)
{
	unsigned width = get_width(), height = get_height();
	Cairo::RefPtr<Cairo::ImageSurface> surface = Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, width, height);
	Cairo::RefPtr<Cairo::Context> cairo = Cairo::Context::create(surface);
	if(HasImage())
	{
		AOLogger::Debug << "Saving PNG of " << get_width() << " x " << get_height() << "\n";
		update(cairo, width, height);
	}
	surface->write_to_png(filename);
}
开发者ID:pkgw,项目名称:aoflagger,代码行数:12,代码来源:imagewidget.cpp

示例5: main

int main (void)
{
    Cairo::RefPtr<Cairo::ImageSurface> surface = Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, WIDTH, HEIGHT);
    Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create(surface);
    draw(cr, WIDTH, HEIGHT);
#ifdef CAIRO_HAS_PNG_FUNCTIONS
    const char* filename = "text-rotate.png";
    surface->write_to_png(filename);
    std::cout << "Wrote file " << filename << std::endl;
#else
    std::cout << "You must compile cairo with PNG support for this example to work" << std::endl;
#endif
}
开发者ID:sheik,项目名称:five-lights,代码行数:13,代码来源:texr.cpp

示例6: main

int main()
{
  Cairo::RefPtr<Cairo::ImageSurface> surface =
    Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, 600, 400);

  Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create(surface);

  cr->save(); // save the state of the context
  cr->set_source_rgb(0.86, 0.85, 0.47);
  cr->paint();   // fill image with the color
  cr->restore(); // color is back to black now

  cr->save();
  // draw a border around the image
  cr->set_line_width(20.0); // make the line wider
  cr->rectangle(0.0, 0.0, surface->get_width(), surface->get_height());
  cr->stroke();

  cr->set_source_rgba(0.0, 0.0, 0.0, 0.7);
  // draw a circle in the center of the image
  cr->arc(surface->get_width() / 2.0, surface->get_height() / 2.0,
          surface->get_height() / 4.0, 0.0, 2.0 * M_PI);
  cr->stroke();

  // draw a diagonal line
  cr->move_to(surface->get_width() / 4.0, surface->get_height() / 4.0);
  cr->line_to(surface->get_width() * 3.0 / 4.0,
              surface->get_height() * 3.0 / 4.0);
  cr->stroke();
  cr->restore();

#ifdef CAIRO_HAS_PNG_FUNCTIONS

  std::string filename = "image.png";
  surface->write_to_png(filename);

  std::cout << "Wrote png file \"" << filename << "\"" << std::endl;

#else

  std::cout
    << "You must compile cairo with PNG support for this example to work."
    << std::endl;

#endif
}
开发者ID:Andreiphontes,项目名称:CMake,代码行数:46,代码来源:main.cpp

示例7: postprocess

  /** Post-process files. Only valid for PNGs. */
  void postprocess()
  {
    printf("Post-processing PNG files, resizing to %fx%f\n", maxwidth, maxheight);
    struct dirent *d;
    DIR *output_dir = opendir(outdir.c_str());
    while ((d = readdir(output_dir)) != NULL) {
      if (fnmatch("*.png", d->d_name, FNM_PATHNAME | FNM_PERIOD) == 0) {
	infile = outdir + "/" + d->d_name;
	Cairo::RefPtr<Cairo::ImageSurface> imgs = Cairo::ImageSurface::create_from_png(infile);
	if ( (imgs->get_height() != maxheight) || (imgs->get_width() != maxwidth)) {
	  // need to re-create
	  char *tmpout = strdup((outdir + "/tmpXXXXXX").c_str());
	  FILE *f = fdopen(mkstemp(tmpout), "w");
	  outfile = tmpout;
	  free(tmpout);

	  Cairo::RefPtr<Cairo::ImageSurface> outs = Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32,
										(int)ceilf(maxwidth),
										(int)ceilf(maxheight));
	  double tx = (maxwidth  - imgs->get_width()) / 2.0;
	  double ty = (maxheight - imgs->get_height()) / 2.0;
	  printf("Re-creating %s for post-processing, "
		 "resizing from %ix%i, tx=%f, ty=%f\n", infile.c_str(),
		 imgs->get_width(), imgs->get_height(), tx, ty);
	  Cairo::RefPtr<Cairo::Context> cc = Cairo::Context::create(outs);
	  if (white_bg) {
	    cc->set_source_rgb(1, 1, 1);
	    cc->paint();
	  }
	  cc->set_source(imgs, tx, ty);
	  cc->paint();
	  outs->write_to_png(&SkillGuiBatchRenderer::write_func, f);
	  imgs.clear();
	  cc.clear();
	  outs.clear();
	  fclose(f);
	  rename(outfile.c_str(), infile.c_str());
	}
      }
    }
    closedir(output_dir);
  }
开发者ID:,项目名称:,代码行数:43,代码来源:

示例8: main

int main(int, char**) {
	Cairo::RefPtr<Cairo::ImageSurface> surface = Cairo::ImageSurface::create(
			Cairo::FORMAT_ARGB32, WIDTH, HEIGHT);
	Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create(surface);
	// fill background in white
	cr->set_source_rgb(1.0, 1.0, 1.0);
	cr->paint();

	// draw a little dot at the point where text will be drawn
	cr->arc(TEXT_ORIGIN_X, TEXT_ORIGIN_Y, FONT_SIZE / 4.0, 0, 2 * M_PI);
	cr->set_source_rgba(0.0, 1.0, 0.0, 0.5);
	cr->fill();

	// draw the text
	cr->move_to(TEXT_ORIGIN_X, TEXT_ORIGIN_Y);
	cr->set_source_rgb(0.8, 0.2, 0.2);
	Cairo::RefPtr<BoxFontFace> font = BoxFontFace::create();
	cr->set_font_face(font);
	cr->set_font_size(FONT_SIZE);
	cr->show_text("cairomm!");

	// Now show it with the toy text API to
	// demonstrate how the glyphs match up
	cr->move_to(TEXT_ORIGIN_X, TEXT_ORIGIN_Y);
	cr->set_source_rgba(0.2, 0.2, 0.2, 0.3);
	Cairo::RefPtr<Cairo::ToyFontFace> toy_font = Cairo::ToyFontFace::create(
			"Bitstream Charter", Cairo::FONT_SLANT_NORMAL,
			Cairo::FONT_WEIGHT_BOLD);
	cr->set_font_face(toy_font);
	cr->set_font_size(FONT_SIZE);
	cr->show_text("cairomm!");

	const char* filename = "user-font.png";
	try {
		surface->write_to_png(filename);
		std::cout << "Wrote Image " << filename << std::endl;
		return 0;
	} catch (const std::exception& e) {
		std::cout << "** Unable to write Image " << filename << std::endl;
		return 1;
	}
}
开发者ID:hamedobaidy,项目名称:cairomm_examples,代码行数:42,代码来源:user_font.cpp

示例9: save_file

	void MainWindow::save_file()
	{
		std::cout << "MainWindow::save_file()\n";

		if(m_png)
		{
			//dane są w obrazie teraz można je zapisać
			//więc dialog i te sprawy
			std::string filename = run_open_file_dialog("Select file to save stegocontener", Gtk::FILE_CHOOSER_ACTION_SAVE);

			std::string test_text = m_text.get_buffer()->get_text();
			m_wavelet.hide_text(test_text);

			if(filename != "")
			{
				std::cout << "Saving image\n";
				Cairo::RefPtr<Cairo::ImageSurface> surface = m_wavelet.to_image().to_cairo_image_surface();
				surface->write_to_png(filename);
			}
		}
	}
开发者ID:rph-pl,项目名称:wavelet-stego,代码行数:21,代码来源:main_window.cpp

示例10: md

/** save current graph. */
void
SkillGuiGraphDrawingArea::save()
{
  Gtk::Window *w = dynamic_cast<Gtk::Window *>(get_toplevel());
  __fcd_save->set_transient_for(*w);

  int result = __fcd_save->run();
  if (result == Gtk::RESPONSE_OK) {

    Gtk::FileFilter *f = __fcd_save->get_filter();
    std::string filename = __fcd_save->get_filename();
    if (filename != "") {
      if (f == __filter_dot) {
	save_dotfile(filename.c_str());
      } else {
	Cairo::RefPtr<Cairo::Surface> surface;

	bool write_to_png = false;
	if (f == __filter_pdf) {
	  surface = Cairo::PdfSurface::create(filename, __bbw, __bbh);
	} else if (f == __filter_svg) {
	  surface = Cairo::SvgSurface::create(filename, __bbw, __bbh);
	} else if (f == __filter_png) {
	  surface = Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32,
						(int)ceilf(__bbw),
						(int)ceilf(__bbh));
	  write_to_png = true;
	}

	if (surface) {
	  __cairo = Cairo::Context::create(surface);
	  
	  bool old_scale_override = __scale_override;
	  double old_tx = __translation_x;
	  double old_ty = __translation_y;
	  double old_scale = __scale;
	  __translation_x = __pad_x;
	  __translation_y = __bbh - __pad_y;
	  __scale = 1.0;
	  __scale_override = true;

	  if (__graph) {
	    gvRender(__gvc, __graph, (char *)"skillguicairo", NULL);
	  }

	  if (write_to_png) {
	    surface->write_to_png(filename);
	  }

	  __cairo.clear();

	  __translation_x = old_tx;
	  __translation_y = old_ty;
	  __scale = old_scale;
	  __scale_override = old_scale_override;
	}
      }

    } else {
      Gtk::MessageDialog md(*w, "Invalid filename",
			    /* markup */ false, Gtk::MESSAGE_ERROR,
			    Gtk::BUTTONS_OK, /* modal */ true);
      md.set_title("Invalid File Name");
      md.run();
    }
  }

  __fcd_save->hide();
}
开发者ID:timn,项目名称:ros-skillgui,代码行数:70,代码来源:graph_drawing_area.cpp

示例11: render_png

int render_png(Graph* graph)
{
	int i_side = (graph->side_length - 1) * SPACING + PADDING;

	//Cairo ImageSurface. This one will be saved afterwards as a png file
	Cairo::RefPtr<Cairo::ImageSurface> surface = Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, i_side + PADDING * 2, i_side + PADDING * 2);
	//Cairo Context.
	Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create(surface);

	cr->save(); // save the state of the context
	cr->set_source_rgb(1.0, 1.0, 1.0);
	cr->paint(); // fill image with the color
	cr->restore(); // color is back to black now

	//Storing state to start drawing
	cr->save();

	//setting brush color to black
	cr->set_source_rgb(0.0, 0.0, 0.0);

	cr->set_line_width(1.0);

	//drawing lines
	for (int i = 0; i < graph->side_length; i++) {
		for (int j = 0; j < graph->side_length; j++) {
			//for a current node
			Node* current = graph->matrix.at(i).at(j);
			//find all friends
			for (int k = 0; k < current->friends.size(); k++) {
				pair<int, int> current_friend = *std::next(current->friends.begin(), k);
				//Move brush to current node
				cr->move_to(current->coors.first * SPACING + PADDING, current->coors.second * SPACING + PADDING);
				//Draw a line to current friend
				cr->line_to(current_friend.first * SPACING + PADDING, current_friend.second * SPACING + PADDING);
				cr->stroke();
			}
		}
	}

	//setting brush color to red
	cr->set_source_rgb(1.0, 0.0, 0.0);

	//drawing vertices after lines are drawn
	for (int i = 0; i < graph->side_length; i++) {
		for (int j = 0; j < graph->side_length; j++) {
			Node* current = graph->matrix.at(i).at(j);
			cr->arc(current->coors.first * SPACING + PADDING, current->coors.second * SPACING + PADDING, 1.0, 0.0, 2.0 * M_PI);
			cr->stroke();
		}
	}

	cr->restore();

#ifdef CAIRO_HAS_PNG_FUNCTIONS

	std::string filename = build_name("result");
	surface->write_to_png(filename);

	std::cout << "Wrote png file \"" << filename << "\"" << std::endl;

#else

	std::cout << "You must compile cairo with PNG support for this example to work."
	          << std::endl;

#endif
}
开发者ID:roornelas,项目名称:small-world,代码行数:67,代码来源:gui.cpp


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