|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Adding images to the databaseLooking for an idea here. I've got a .Net app connecting to SQL2005 where I
allow users to add pictures to the database. But I don't want them adding gigantic images, so I'm looking for an idea on how to control how big of an image they might add. I'm not interested in simply saving a pointer to a file here. varbinary (max) would automatically limit them to 2 GB size, but your best
bet might be to check the size on the client side if you want to limit them to say 10 MB or something. If you send it to the server first, someone might have just spent all that time uploading a 100 MB file only to have it error on them. That's a waste of time and bandwidth. If you want to ensure that, for instance, your developers can't work their way around the system and bypass the client app to insert larger files you might look into triggers as well. Show quote "Earl" <brikshoe@newsgroups.nospam> wrote in message news:%23eO12zNFHHA.3608@TK2MSFTNGP03.phx.gbl... > Looking for an idea here. I've got a .Net app connecting to SQL2005 where > I allow users to add pictures to the database. But I don't want them > adding gigantic images, so I'm looking for an idea on how to control how > big of an image they might add. I'm not interested in simply saving a > pointer to a file here. > Earl,
the most easiest way is in my idea to use the thumbnail. In this sample is that used. Dim fo As New OpenFileDialog If fo.ShowDialog = DialogResult.OK Then PictureBox1.Image = PictureBox1.Image.FromFile(fo.FileName) Dim Thumbnail As System.drawing.Image = _ PictureBox1.Image.GetThumbnailImage(32, 32, Nothing, New IntPtr) PictureBox2.Image = Thumbnail End If I hope this helps, Cor Show quote "Earl" <brikshoe@newsgroups.nospam> schreef in bericht news:%23eO12zNFHHA.3608@TK2MSFTNGP03.phx.gbl... > Looking for an idea here. I've got a .Net app connecting to SQL2005 where > I allow users to add pictures to the database. But I don't want them > adding gigantic images, so I'm looking for an idea on how to control how > big of an image they might add. I'm not interested in simply saving a > pointer to a file here. > Hi!
If you wish for the image to be anything else than a thumbnail I would suggest that you resize the image instead of using the GetThumbnailImage. Resizing the image is pretty simple Here is an example. Bitmap bmp = new Bitmap(uploadedImage, newWidth, newHeight); bmp.Save(myStream, System.Drawing.Imaging.ImageFormat.Png) You can also use encoding parameters to save the image in order to change compression and such. Then just remember that you can user System.Drawing.Imaging.ImageFormat.<imagetype>.Guid to get the correct guid for the encoder. Good luck! //Micke Show quote "Cor Ligthert [MVP]" wrote: > Earl, > > the most easiest way is in my idea to use the thumbnail. > > In this sample is that used. > Dim fo As New OpenFileDialog > If fo.ShowDialog = DialogResult.OK Then > PictureBox1.Image = PictureBox1.Image.FromFile(fo.FileName) > Dim Thumbnail As System.drawing.Image = _ > PictureBox1.Image.GetThumbnailImage(32, 32, Nothing, New IntPtr) > PictureBox2.Image = Thumbnail > End If > > > I hope this helps, > > Cor > > > "Earl" <brikshoe@newsgroups.nospam> schreef in bericht > news:%23eO12zNFHHA.3608@TK2MSFTNGP03.phx.gbl... > > Looking for an idea here. I've got a .Net app connecting to SQL2005 where > > I allow users to add pictures to the database. But I don't want them > > adding gigantic images, so I'm looking for an idea on how to control how > > big of an image they might add. I'm not interested in simply saving a > > pointer to a file here. > > > > > Thanks to all, Mike, Mikael and Cor. Looks like I'm going to resize on the
client side using the new Width and Height. I can certainly see uses for thumbnails though. Show quote "Mikael Gustavsson" <MikaelGustavs***@discussions.microsoft.com> wrote in message news:2497ED03-EA23-4DF6-8581-A2E0382CAFE7@microsoft.com... > Hi! > > If you wish for the image to be anything else than a thumbnail I would > suggest that you resize the image instead of using the GetThumbnailImage. > Resizing the image is pretty simple Here is an example. > > Bitmap bmp = new Bitmap(uploadedImage, newWidth, newHeight); > bmp.Save(myStream, System.Drawing.Imaging.ImageFormat.Png) > > You can also use encoding parameters to save the image in order to change > compression and such. Then just remember that you can user > System.Drawing.Imaging.ImageFormat.<imagetype>.Guid to get the correct > guid > for the encoder. > > Good luck! > > //Micke > > "Cor Ligthert [MVP]" wrote: > >> Earl, >> >> the most easiest way is in my idea to use the thumbnail. >> >> In this sample is that used. >> Dim fo As New OpenFileDialog >> If fo.ShowDialog = DialogResult.OK Then >> PictureBox1.Image = PictureBox1.Image.FromFile(fo.FileName) >> Dim Thumbnail As System.drawing.Image = _ >> PictureBox1.Image.GetThumbnailImage(32, 32, Nothing, New IntPtr) >> PictureBox2.Image = Thumbnail >> End If >> >> >> I hope this helps, >> >> Cor >> >> >> "Earl" <brikshoe@newsgroups.nospam> schreef in bericht >> news:%23eO12zNFHHA.3608@TK2MSFTNGP03.phx.gbl... >> > Looking for an idea here. I've got a .Net app connecting to SQL2005 >> > where >> > I allow users to add pictures to the database. But I don't want them >> > adding gigantic images, so I'm looking for an idea on how to control >> > how >> > big of an image they might add. I'm not interested in simply saving a >> > pointer to a file here. >> > >> >> >> |
|||||||||||||||||||||||