Results 1 to 15 of 15

Thread: [RESOLVED] [2008] Border for images

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    515

    Resolved [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.

  2. #2
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    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
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    515

    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:


  4. #4
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    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)
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  5. #5
    Hyperactive Member gnaver's Avatar
    Join Date
    Jul 2005
    Location
    Denmark/Sweden
    Posts
    289

    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 ...

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    515

    Re: [2008] Border for images

    Quote 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

  7. #7
    Hyperactive Member gnaver's Avatar
    Join Date
    Jul 2005
    Location
    Denmark/Sweden
    Posts
    289

    Re: [2008] Border for images

    yep you can do that

    heres an quick example::

    vb Code:
    1. Dim img As New Bitmap(200, 200)
    2.         Dim g As Graphics = Graphics.FromImage(img)
    3.         g.DrawImage(New Bitmap("c:\border.jpg"), New Rectangle(0, 0, 200, 200))
    4.         g.DrawImage(New Bitmap("c:\image.jpg"), New Rectangle(20, 20, 160, 160))
    5.         'SHOW THE NEW IMAGE
    6.         PictureBox1.Image = img
    7.         'Saves the image
    8.         img.Save("c:\newimage.jpg")

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    515

    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 ?

  9. #9
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: [2008] Border for images

    wow I never knew GDI stuff could be that simple, thanks for the example gnaver
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    515

    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.

    Quote 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

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    515

    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 ?

  12. #12
    Hyperactive Member gnaver's Avatar
    Join Date
    Jul 2005
    Location
    Denmark/Sweden
    Posts
    289

    Re: [RESOLVED] [2008] Border for images

    dont know if this is what you want?

    vb Code:
    1. Dim img As New Bitmap(200, 200)
    2.  
    3.  
    4.         Using g As Graphics = Graphics.FromImage(img)
    5.             g.DrawImage(New Bitmap("c:\border.jpg"), New Rectangle(0, 0, 200, 200))
    6.             g.DrawImage(New Bitmap("c:\image.jpg"), New Rectangle(10, 30, 180, 138))
    7.             g.DrawImage(New Bitmap("c:\logo.gif"), New Rectangle(200 - 50, 0, 50, 50))
    8.  
    9.         End Using
    10.         'SHOW THE NEW IMAGE
    11.         PictureBox1.Image = img
    12.         'Saves the image
    13.         img.Save("c:\newimage.jpg")

    also instead of gif you should use png as they support more colors

  13. #13
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: [2008] Border for images

    Quote 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.

  14. #14

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    515

    Re: [2008] Border for images

    Quote 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.

  15. #15

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    515

    Re: [RESOLVED] [2008] Border for images

    Quote 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
  •  



Click Here to Expand Forum to Full Width