http://www.vbforums.com/attachment.p...1&d=1211970761
I need to thumbnail an image and add a border like this to thumbnail using code.
Can anyone help me with how this is done ?
Printable View
http://www.vbforums.com/attachment.p...1&d=1211970761
I need to thumbnail an image and add a border like this to thumbnail using code.
Can anyone help me with how this is done ?
Does it have to be that exact border? You can set the BorderStyle property of your picturebox control to FixedSingle if you just want to add a thin black border
No, I know what you mean but I'm trying to add a custom filmstrip border to an image like this:
http://tbn0.google.com/images?q=tbn:...ip_153x150.jpg
Erm the only way I can think of doing it is by laying the picture box with your thumbnail image in over the top of the picturebox that has the filmstrip border in but thats a bad and probably unreliable way of doing it so wait and see if anyone else has a better idea (im sure they will do)
draw the border image to the picturebox using GDI, and then draw the thumb image on top on it also using GDI ;)...
Smoking cool. How ?Quote:
Originally Posted by gnaver
Can I also save the gdi image as another image say, imagewithborder.jpg/bmp/etc
yep you can do that
heres an quick example::
vb Code:
Dim img As New Bitmap(200, 200) Dim g As Graphics = Graphics.FromImage(img) g.DrawImage(New Bitmap("c:\border.jpg"), New Rectangle(0, 0, 200, 200)) g.DrawImage(New Bitmap("c:\image.jpg"), New Rectangle(20, 20, 160, 160)) 'SHOW THE NEW IMAGE PictureBox1.Image = img 'Saves the image img.Save("c:\newimage.jpg")
Super cool. I guess I don't really need the picture box ? I can just comment out that line and just get gdi to overlay picture on border and save to new image, right ?
wow I never knew GDI stuff could be that simple, thanks for the example gnaver
Yes gnaver, where have you been hiding. Thanks for that wisdom. Only catch I have is disposing the graphics properly.
Quote:
Originally Posted by jmcilhinney
Code:Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim img As New Bitmap(200, 200)
Using g As Graphics = Graphics.FromImage(img)
g.DrawImage(New Bitmap("c:\border.jpg"), New Rectangle(0, 0, 200, 200))
g.DrawImage(New Bitmap("c:\sunset.jpg"), New Rectangle(10, 30, 180, 138))
End Using
'SHOW THE NEW IMAGE
PictureBox1.Image = img
'Saves the image
img.Save("c:\newimage.jpg")
End Sub
gnaver, one more question.
I have a transparent gif that I want to overlay as watermark/logo on an image.
It should be positioned on the top right corner of the image. Can you please show me how to do that ?
dont know if this is what you want?
vb Code:
Dim img As New Bitmap(200, 200) Using g As Graphics = Graphics.FromImage(img) g.DrawImage(New Bitmap("c:\border.jpg"), New Rectangle(0, 0, 200, 200)) g.DrawImage(New Bitmap("c:\image.jpg"), New Rectangle(10, 30, 180, 138)) g.DrawImage(New Bitmap("c:\logo.gif"), New Rectangle(200 - 50, 0, 50, 50)) End Using 'SHOW THE NEW IMAGE PictureBox1.Image = img 'Saves the image img.Save("c:\newimage.jpg")
also instead of gif you should use png as they support more colors ;)
the built in .net garbage disposal system will .dispose all variables when you exit the sub.Quote:
Originally Posted by Xancholy
Apparently there are some memory leak issues. "Using" is what the experts recommend.Quote:
Originally Posted by .paul.
Gnaver, thanks, that looks pretty simple. Do you know how to extract a thumbnail from the new saved image ?Quote:
Originally Posted by gnaver
Or is it possible to save the newimage.jpg as a smaller thumbnail sized 133x100 image ?Code:img.Save("c:\newimage.jpg")