Actually the code worked the problem I was having is that I had to set the resolution of the first image to the same resolution of the final image. Here is the cleaned up code. This code takes an image and places it on a black background. This will give you a final image 400X400. You have to put in the adjustment if the first image is over 400X400.
Dim imgSource As System.Drawing.Image = System.Drawing.Image.FromFile(PathFileName)
Dim bmp As New System.Drawing.Bitmap(imgSource, 200, 200)
bmp.SetResolution(72, 72)
'Create a new Bitmap and Graphics object to write too.
Dim OutPutBitMap As Bitmap = New Bitmap(400, 400)
Dim OutPutGraphics As Graphics = Graphics.FromImage(OutPutBitMap)
OutPutGraphics.Clear(System.Drawing.ColorTranslato r.FromHtml("Black"))
OutPutGraphics.DrawImageUnscaled(bmp, 0, 0)
OutPutBitMap.SetResolution(72, 72)
OutPutBitMap.Save(PathFileName, System.Drawing.Imaging.ImageFormat.Jpeg)
Me.Image1.ImageUrl = PathFileName
|