Page 1 of 1

Resizing and Pasting into new image

Posted: 2010-02-21T08:22:24-07:00
by steveq
Hey All,

I think this is a simple question! :-)

I am writing software for Digital Cinema Packages (DCPs) and it is pretty much complete.
I was using the CxImage class for my image manipulation, but given that ImageMagick supports dpx files, I was thinking of switching over to it.
I also need to do a colour transformation for RGB to XYZ (gamma 2.6), however I have written my own class to do this.

I have successfully loaded an image and resized it:

Code: Select all

Image img;

	try
	{
		img.read( "Dancing.jpg" );

		img.sample( Geometry(1998,1080));
	}

etc...

I would now like create a black image and paste the resized image into the centre of it (The image is portrait so it will have black borders).

I also need to save this 8 bit image as a 16 bit TIF file. I'm also not sure how to do this?

Could someone please give me some guidance on how to do this?

Many thanks,

Steve Q.

Re: Resizing and Pasting into new image

Posted: 2010-02-21T08:27:51-07:00
by magick
Use resize() rather than sample() to get superior results.

Use depth(8) to set your image to 8-bits.

To save to TIFF, use write() with a filename with a TIFF extention (.e.g. image.tif).

Use composite() with an OverCompositeOp operator to composite an image over a background image.

Re: Resizing and Pasting into new image

Posted: 2010-02-21T08:36:06-07:00
by steveq
Hey magick,

That is the fastest reply I have ever had from ANY forum ever! Thanks so much.

I have tried this:

Code: Select all

		img.read( "Dancing.jpg" );

		img.resize( Geometry(1998,1080));

		img.depth(16);

		img.write( "Dancing_resized_16bpp.tif" );
However I get an unhandled exception?

I want to create a 16bit image from the resized 8 bit image and save it as a 16bit TIF.

Also how do I create a new black image at a given resolution? (for the composite call)?

Thanks heaps,

Steve Q.

Re: Resizing and Pasting into new image

Posted: 2010-02-21T08:56:49-07:00
by magick
You need to catch exceptions and print them so you know what ImageMagick is complaining about. Its possible your instance of ImageMagick does not include TIFF support. Type
  • convert -list format
and make sure TIFF is listed with a mode of rw-. If not, you'll need to rebuild / reinstall ImageMagick with TIFF support.

To get a black image to composite on, create an image and set its size with Geometry() and use backgroundColor() to set its color. Download the source and take a look at ImageMagick-6.5.9-9/Magick++/demo and ImageMagick-6.5.9-9/Magick++/test for example Magick++ demos.

Re: Resizing and Pasting into new image

Posted: 2010-02-21T09:03:53-07:00
by steveq
Hey magick,

Thanks again for your help.

Strange, however this works:

Code: Select all

	Image img;
	
	Image img2( "1998x1080", "black" );

	try
	{
		img.read( "Dancing.jpg" );

		img.resize( Geometry(1998,1080));

		img2.depth(16);

		img2.composite( img, 100, 0, OverCompositeOp );

		img2.write( "Dancing_resized_16bpp.tif" );

		AfxMessageBox( _T("Image loaded") );
	}

	catch ( Error& my_error )
	{
		CString error;

		error = my_error.what();

		AfxMessageBox( error );
	}

	catch ( ... )
	{
		AfxMessageBox( _T("Unhandled Error") );
	}
I don't know why my previous example crashed without falling into my catch?

Thanks for the info on creating a new image. I'll probably modify my code and use what you have suggested.

Thanks again for your help.

Steve Q.
:-)