Page 1 of 1

How can resize screenshot?

Posted: Sun Jul 25, 2010 6:36 pm
by full_newbie
This code for create screenshot:

Code: Select all

video::IImage* image = device->getVideoDriver()->createScreenShot();
		if (image)
		{
			device->getVideoDriver()->writeImageToFile(image, "screenshot.bmp");
			device->getVideoDriver()->writeImageToFile(image, "screenshot.png");
			device->getVideoDriver()->writeImageToFile(image, "screenshot.tga");
			device->getVideoDriver()->writeImageToFile(image, "screenshot.ppm");
			device->getVideoDriver()->writeImageToFile(image, "screenshot.jpg");
			device->getVideoDriver()->writeImageToFile(image, "screenshot.pcx");
			image->drop();
		}
but how resize this image?
For example 100*100?

Posted: Sun Jul 25, 2010 7:25 pm
by d3jake
What are you trying to use the image for? Do you mean resize it for use in the game? Resize it so no matter which resolution you capture at it will always be 100^2?

Posted: Sun Jul 25, 2010 7:39 pm
by full_newbie
I need create a mini screenshot.
For example my screen 1024*768 and i am getting screenshot 1024*768, but i need 100*80.
I am add in Irrlicht source:
COpenGLDriver.cpp:

Code: Select all

IImage* COpenGLDriver::createScreenShot(int width,int height)
{
	IImage* newImage = new CImage(ECF_R8G8B8, core::dimension2d<u32>(width,height));

	u8* pixels = static_cast<u8*>(newImage->lock());
	if (!pixels)
	{
		newImage->drop();
		return 0;
	}

	// allows to read pixels in top-to-bottom order
#ifdef GL_MESA_pack_invert
	if (FeatureAvailable[IRR_MESA_pack_invert])
		glPixelStorei(GL_PACK_INVERT_MESA, GL_TRUE);
#endif

	// We want to read the front buffer to get the latest render finished.
	glReadBuffer(GL_FRONT);
	glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, pixels);
	glReadBuffer(GL_BACK);

#ifdef GL_MESA_pack_invert
	if (FeatureAvailable[IRR_MESA_pack_invert])
		glPixelStorei(GL_PACK_INVERT_MESA, GL_FALSE);
	else
#endif
	{
		// opengl images are horizontally flipped, so we have to fix that here.
		const s32 pitch=newImage->getPitch();
		u8* p2 = pixels + (height - 1) * pitch;
		u8* tmpBuffer = new u8[pitch];
		for (u32 i=0; i < height; i += 2)
		{
			memcpy(tmpBuffer, pixels, pitch);
			memcpy(pixels, p2, pitch);
			memcpy(p2, tmpBuffer, pitch);
			pixels += pitch;
			p2 -= pitch;
		}
		delete [] tmpBuffer;
	}

	newImage->unlock();

	if (testGLError())
	{
		newImage->drop();
		return 0;
	}

	return newImage;
}
but i getting a small part screenshot, instead of all screenshot.
My knowledge in OpenGL and DirectX is very small! please help

Posted: Sun Jul 25, 2010 8:53 pm
by Acki
IImage has a pretty usefull function for this: copyToScaling

Posted: Sun Jul 25, 2010 10:28 pm
by full_newbie
Thank you Acki