|
-
Jun 13th, 2008, 07:30 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] [2008] Border for images

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 ?
Last edited by Xancholy; Jun 13th, 2008 at 08:06 AM.
-
Jun 13th, 2008, 07:45 AM
#2
Re: [2008] Border for images
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
-
Jun 13th, 2008, 08:04 AM
#3
Thread Starter
Fanatic Member
Re: [2008] Border for images
No, I know what you mean but I'm trying to add a custom filmstrip border to an image like this:
-
Jun 13th, 2008, 08:11 AM
#4
Re: [2008] Border for images
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)
-
Jun 13th, 2008, 08:35 AM
#5
Hyperactive Member
Re: [2008] Border for images
draw the border image to the picturebox using GDI, and then draw the thumb image on top on it also using GDI ...
-
Jun 13th, 2008, 09:48 AM
#6
Thread Starter
Fanatic Member
Re: [2008] Border for images
 Originally Posted by gnaver
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 ?
Can I also save the gdi image as another image say, imagewithborder.jpg/bmp/etc
-
Jun 13th, 2008, 10:04 AM
#7
Hyperactive Member
Re: [2008] Border for images
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")
-
Jun 13th, 2008, 10:31 AM
#8
Thread Starter
Fanatic Member
Re: [2008] Border for images
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 ?
-
Jun 13th, 2008, 10:34 AM
#9
Re: [2008] Border for images
wow I never knew GDI stuff could be that simple, thanks for the example gnaver
-
Jun 13th, 2008, 10:50 AM
#10
Thread Starter
Fanatic Member
Re: [2008] Border for images
Yes gnaver, where have you been hiding. Thanks for that wisdom. Only catch I have is disposing the graphics properly.
 Originally Posted by jmcilhinney
Using gr As Graphics = Graphics.FromImage(bmp)
'Use gr here.
End Using[/HIGHLIGHT]Just think of the "Using" key word as a replacement for "Dim" and when you hit Enter at the end of the line the IDE will add the End Using for you.
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
-
Jun 17th, 2008, 04:55 PM
#11
Thread Starter
Fanatic Member
Re: [RESOLVED] [2008] Border for images
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 ?
-
Jun 17th, 2008, 05:05 PM
#12
Hyperactive Member
Re: [RESOLVED] [2008] Border for images
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
-
Jun 17th, 2008, 05:25 PM
#13
Re: [2008] Border for images
 Originally Posted by Xancholy
Only catch I have is disposing the graphics properly.
the built in .net garbage disposal system will .dispose all variables when you exit the sub.
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jun 17th, 2008, 06:20 PM
#14
Thread Starter
Fanatic Member
Re: [2008] Border for images
 Originally Posted by .paul.
the built in .net garbage disposal system will .dispose all variables when you exit the sub.
Apparently there are some memory leak issues. "Using" is what the experts recommend.
-
Jun 17th, 2008, 06:23 PM
#15
Thread Starter
Fanatic Member
Re: [RESOLVED] [2008] Border for images
 Originally Posted by gnaver
dont know if this is what you want?
Gnaver, thanks, that looks pretty simple. Do you know how to extract a thumbnail from the new saved image ?
Code:
img.Save("c:\newimage.jpg")
Or is it possible to save the newimage.jpg as a smaller thumbnail sized 133x100 image ?
Last edited by Xancholy; Jun 17th, 2008 at 06:27 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|