Esempio n. 1
0
/* based on screendump.c::screenshot_exec */
void BL_MakeScreenShot(ScrArea *curarea, const char* filename)
{
	char path[MAX_FILE_LENGTH];
	strcpy(path,filename);

	unsigned int *dumprect;
	int dumpsx, dumpsy;
	
	dumprect= screenshot(curarea, &dumpsx, &dumpsy);
	if(dumprect) {
		ImBuf *ibuf;
		BLI_path_abs(path, G.main->name);
		/* BKE_add_image_extension() checks for if extension was already set */
		BKE_add_image_extension(path, R_IMF_IMTYPE_PNG); /* scene->r.im_format.imtype */
		ibuf= IMB_allocImBuf(dumpsx, dumpsy, 24, 0);
		ibuf->rect= dumprect;
		ibuf->ftype= PNG;

		IMB_saveiff(ibuf, path, IB_rect);

		ibuf->rect= NULL;
		IMB_freeImBuf(ibuf);
		MEM_freeN(dumprect);
	}
}
Esempio n. 2
0
static int screenshot_exec(bContext *C, wmOperator *op)
{
	ScreenshotData *scd= op->customdata;

	if(scd == NULL) {
		/* when running exec directly */
		screenshot_data_create(C, op);
		scd= op->customdata;
	}

	if(scd) {
		if(scd->dumprect) {
			Scene *scene= CTX_data_scene(C);
			ImBuf *ibuf;
			char path[FILE_MAX];

			RNA_string_get(op->ptr, "filepath", path);

			BLI_strncpy(G.ima, path, sizeof(G.ima));
			BLI_path_abs(path, G.main->name);

			/* BKE_add_image_extension() checks for if extension was already set */
			if(scene->r.scemode & R_EXTENSION)
				if(strlen(path)<FILE_MAX-5)
					BKE_add_image_extension(path, scene->r.im_format.imtype);

			ibuf= IMB_allocImBuf(scd->dumpsx, scd->dumpsy, 24, 0);
			ibuf->rect= scd->dumprect;

			/* crop to show only single editor */
			if(!RNA_boolean_get(op->ptr, "full"))
				screenshot_crop(ibuf, scd->crop);

			BKE_write_ibuf(ibuf, path, &scene->r.im_format);

			IMB_freeImBuf(ibuf);
		}
	}

	screenshot_data_free(op);
	return OPERATOR_FINISHED;
}