Hi All,
I have a desktop app that allows the user to save images to the database, the images are used to display on our website. I would like to scale down the image before it is saved. I know I can use the graphics class to reduce the size / resolution, but how can I reduce the dpi so that the physical size of the image can reduce further as I do not need to print it out, lower dpi does not affect the image shown on the website.
Thanks in advance.
Read the xxResolution Properties here .
(New Picture at lower Resolution / draw larger image into the lower image / store the lower image)
[quote=363205:@Tony Lam]Hi All,
I have a desktop app that allows the user to save images to the database, the images are used to display on our website. I would like to scale down the image before it is saved. I know I can use the graphics class to reduce the size / resolution, but how can I reduce the dpi so that the physical size of the image can reduce further as I do not need to print it out, lower dpi does not affect the image shown on the website.
Thanks in advance.[/quote]
You do understand that lowering the dpi without changing the physical dimensions will actually increase the display size right?
72px @ 72dots per inch = 1
72px @ 36 dots per inch = 2
My guess from your note is that sometimes you are getting images that are 300dpi. In that case, youll want to do some math…
dim p as picture = original
dim sf as double = 72 / 300
Dim newpic as new picture(p.width*sf, p.height*sf)
Draw the picture onto that new image. It defaults to 72x72 dpi so youll get what youre looking for.
Hi Greg,
I tried with your suggested math calculation:
dim p as picture = image1.Image //i have an image that allow file drop without any resizing
dim sf as double = 72 / 300
Dim newpic as new picture(p.width*sf, p.height*sf)
//how do I assign the picture content of p to new pic?
dim folder as new FolderItem
dim file as new FolderItem
folder.name = "c:\\temp"
file = folder.child("test.jpg")
newpic.Save(file, picture.SaveAsJPEG)
How do I assign the picture content of p to new pic?
quickly out of my memory
Dim newpic as new picture(p.width*sf, p.height*sf)
newpic.Graphics.DrawPicture(p, 0, 0, p.Width * sf, p.Height * sf, 0, 0, p.Width, p.Height)
Thanks Greg and Axel, it works for me.