Single Image Sprite

Hi Aspose Community,

Now, I need to create a kind of special image "sprite" using Aspose.Imaging.

The idea is using the same image source performs several resizes and at the final I need to have a single image file with all different resizes performed.

Steps!

Step 01) Load the source image file. (keep the aspect-ratio and image quality).

Step 02) Execute my resizes and save t in some area.
<Dimensions>
<string>16,16</string>
<string>20,20</string>
<string>24,24</string>
...
</Dimensions>

Step 03) Calculate my image canvas and save all resized images in the same line in a final image file.

Do you guys have some example of something like that in the current documentation or some object/method that could perform these actions for me?

Done!

It is almost done, now I need only something that merges my images in the final into a single image. Everything in the same line.

Hi Ygor,


Thank you for considering Aspose APIs.

You may use the Aspose.Imaging.Graphics.DrawImage method or its other variations such as DrawImageUnscaled & DrawImageUnscaledAndClipped for your requirements of drawing re-sized images on a new canvas. Please check the following piece of code that creates a blank canvas of 500x500 and uses the Graphics.DrawImage to draw an image loaded from the disk. I have commented the code so you may easily amend it according to you application needs.

Please feel free to contact us back in case you need our further assistance with Aspose APIs.

C#

//Create an instance of BmpOptions and set its various properties
Aspose.Imaging.ImageOptions.BmpOptions ImageOptions = new Aspose.Imaging.ImageOptions.BmpOptions();
ImageOptions.BitsPerPixel = 24;

//Create an instance of FileCreateSource and assign it to Source property
ImageOptions.Source = new Aspose.Imaging.Sources.FileCreateSource(“D:/sample.bmp”, false);

//Create an instance of Image while specifying the desired dimensions
using (var image = Aspose.Imaging.Image.Create(ImageOptions, 500, 500))
{
//Create and initialize an instance of Graphics
var graphics = new Aspose.Imaging.Graphics(image);

//Clear the image surface with white color
graphics.Clear(Color.White);

//Draw an image on blank canvas
graphics.DrawImage(Image.Load(“D:/image001.png”), new Point(0, 0));

//Save changes
image.Save();
}