Double Image Size Code RRS feed

  • Question

  • User-1585994330 posted
    is there way of doubling an image size on upload. I know how to resize an image to a set max width / height but if the image is too small is there a way of doubling its size, OR is there a way of creating an image which is say 300 wide by 200 high and have the parts which aren't the image im resizing are transparent? Thanks for any / all help / advice / tips / links Simon
    Saturday, October 25, 2008 8:10 PM

All replies

  • User-627724879 posted

    Stretching an image will of course pixilate the image and make it not so good. Yes you should be able to create an image in the size you want and add the uploaded image on top of the transparent image.


    I am trying to find some code to overlay one image on the other, but I am not finding it. I will see what I can find tomorrow.

    Sunday, October 26, 2008 12:17 AM
  • User-1585994330 posted
    right, ive nearly sorted it, but a small issue keeps persisting. At the moment it gets my transparent canvas image, and draws my image in the middle of it. but the transparency goes after its saved and the background is black :(

    can you tell me why // how to keep the background transparent?

    System.Drawing.Image imgPhoto = System.Drawing.Image.FromFile(Server.MapPath(@"~/PictureThis/trans.gif"));
    int phWidth = imgPhoto.Width;
    int phHeight = imgPhoto.Height;
    System.Drawing.Image imgWatermark = new Bitmap(Server.MapPath(@"~/PictureThis/2/15751.jpg"));
    int wmWidth = imgWatermark.Width;
    int wmHeight = imgWatermark.Height;
    Bitmap bmPhoto = new Bitmap(phWidth, phHeight);
    bmPhoto.SetResolution(72, 72);
    Graphics grPhoto = Graphics.FromImage(bmPhoto);
    Bitmap bmWatermark = new Bitmap(bmPhoto);
    bmWatermark.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);
    Graphics grWatermark = Graphics.FromImage(bmWatermark);
    ImageAttributes imageAttributes = new ImageAttributes();
    int xPosOfWm = (phWidth / 2) - (wmWidth / 2);
    int yPosOfWm = (phHeight / 2) - (wmHeight / 2);
    grWatermark.DrawImage(imgWatermark, new Rectangle(xPosOfWm, yPosOfWm, wmWidth, wmHeight), 0, 0, wmWidth, wmHeight, GraphicsUnit.Pixel,imageAttributes);
    imgPhoto = bmWatermark; imgPhoto.Save(Server.MapPath(@"~/PictureThis/3/Testing.jpg"), ImageFormat.Jpeg);

    Thanks in advance! Si
    Sunday, October 26, 2008 7:40 AM