Add transparent border around image (resize image)

Jan 3, 2012 at 4:45 PM

Hello,

I use Image Tools for WP7.1 and I am very new to Image Tools. I have been able to use Image Tools for some simple operations (cropping), but now I am stuck at this point.

I have a PNG image with transparency that has a height and width of 100pixels. I am able to load this image into an ExtendedImage.

Now I would like to have an image with the dimensions 173x173, but I would prefer not to enlarge the image because that would decrease the quality. Instead, I would like to add a transparent border around the original 100x100 image.

How can I do that?

Jan 3, 2012 at 9:36 PM

Well I was able to achive what I wanted by simply copying pixel for pixel to the new Image.

I had two ExtendedImages, image1 (100x100, containing an actual image) and image2 (173*173, empty) and I used this code:

for (int i0 = 37; i0 < 137; i0++)
{
     int i1 = i0 - 37;
     for (int j0 = 37; j0 < 137; j0++)
     {
          int j1 = j0 - 37;
          for (int k = 0; k < 4; k++)
          {
               image2.Pixels[(i0 * 4) + (j0 * 4) * 173 + k] = image1.Pixels[(i1 * 4) + (j1 * 4) * 100 + k];
          }
     }
}

I guess I can probably use Array.Copy() somewhere, but at least it is working now.

Jan 4, 2012 at 5:27 AM
Looks great. Another option would be to render your image into a canvas
and save this canvas as an image.
Jan 17, 2014 at 1:14 AM
Image cropping goes different from image resizing, your post title is on image resizing, while your post content says on image cropping. For offering you the comprehensive image editing solutions, including image resizing and cropping, you'd better apply an image manipulating tool which can give the detailed guide on image resizing.