Results 1 to 30 of 30

Thread: Making Picture With VB

  1. #1

    Thread Starter
    Registered User
    Join Date
    Jul 2001
    Location
    israel
    Posts
    81

    Making Picture With VB

    Hello everybody!

    I Want to know if there is a way to take a picture (jpg,gif) from VB and add Writing to that picture save it and have a new picture.

    10x

  2. #2
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236
    Yes you can but it will save as a BMP.

    VB Code:
    1. Sub Form_Load()
    2.  
    3. Picture1.Picture = LoadPicture(App.Path & "\My Pic.jpg")
    4.  
    5. End Sub
    6.  
    7. Private Sub cmdAddText_Click()
    8.  
    9. Picture1.AutoRedraw = True
    10. Picture1.CurrentX = Picture1.Height / 2 'X Position you want to print text
    11. Picture1.CurrentY = Picture1.Width / 2 'Y Position you want to print text
    12. Picture1.FontSize = 16
    13. Picture1.ForeColor = vbRed
    14. Picture1.Print "This is a sample"
    15.  
    16. End Sub
    17.  
    18. Private Sub cmdSave_Click()
    19.  
    20. SavePicture Picture1.Image,  App.Path & "\Test.bmp"   ' Save picture to file.
    21.  
    22. End Sub
    Last edited by Keithuk; Dec 29th, 2004 at 05:45 PM.
    Keith

    I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

  3. #3
    Hyperactive Member DovyWeiss's Avatar
    Join Date
    Feb 2002
    Location
    Miami Beach, FL
    Posts
    366
    In that example, it should be ScaleWidth and ScaleHeight, not Width and Height. (Because the ScaleMode of the PictureBox could be different than that of the parent Form.)

    Also, if you're done, please add [Resolved] to the title...

    And if you absolutely need to save as a jpg, there are free jpg libraries around.

  4. #4

    Thread Starter
    Registered User
    Join Date
    Jul 2001
    Location
    israel
    Posts
    81
    Thank you Keithuk!

    DovyWeiss i have saved to a bmp and to jpg and it seems to be very big (bytes) where and what are Jpg libraries and where can i get them ?

  5. #5
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236
    Thank you DovyWeiss, my mistake.

    I originally used
    Picture1.CurrentX = 2000
    Picture1.CurrentY = 2000

    Then I thought lets put it in the centre but I didn't try it.

    Last edited by Keithuk; Dec 5th, 2004 at 09:23 AM.
    Keith

    I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

  6. #6

    Thread Starter
    Registered User
    Join Date
    Jul 2001
    Location
    israel
    Posts
    81
    Originally posted by asi
    Thank you Keithuk!

    DovyWeiss i have saved to a bmp and to jpg and it seems to be very big (bytes) where and what are Jpg libraries and where can i get them ?
    Do Anybodu have an idea ?

  7. #7
    Addicted Member
    Join Date
    May 2004
    Location
    China
    Posts
    228
    You know the best way to find the answer to your question? SEARCH!
    www.google.com
    www.planet-source-code.com
    www.msdn.com
    http://www.vbforums.com/search.php?s=
    P.S. Its faster than waiting for replies too!

    [vbcode]
    If InStr(1, Message, "FIX MY CODE") <> 0 Then Reply = False
    If AnswerIn(Google, VB_Forums, PSC, MSDN) = True Then Reply = False
    [/vbcode]

  8. #8

    Thread Starter
    Registered User
    Join Date
    Jul 2001
    Location
    israel
    Posts
    81
    Originally posted by asi
    Thank you Keithuk!

    DovyWeiss i have saved to a bmp and to jpg and it seems to be very big (bytes) where and what are Jpg libraries and where can i get them ?
    help !!!
    i need an answer.

  9. #9

  10. #10
    Frenzied Member ae_jester's Avatar
    Join Date
    Jun 2001
    Location
    Kitchener Ontario Canada Earth
    Posts
    1,545
    I've attached a Bmp2Jpeg DLL which I use in many projects to convert images between bmp and jpg. Works great!

    To use it:

    VB Code:
    1. Private Declare Function BmpToJpeg Lib "Bmp2Jpeg.dll" _
    2.     (ByVal bmpFileName As String, ByVal JpegFilename As String, _
    3.      ByVal CompressQuality As Integer) As Integer
    4.  
    5. 'To convert an image
    6. Call BmpToJpeg(strBmpFileName, strJpgFileName, 100) 'the last parameter is the picture quality (compression)

  11. #11

  12. #12
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654
    Well, you don't need to reference it, just have it in the app's path or Windows' System folder.

  13. #13

  14. #14
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654
    A lot depends on current path, when VB starts, the current path is VB's path (the one defined in the shortcut icon). So once the current path changed to code path where the dll is, it started to work.

    Just my guess

  15. #15
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111
    Right... if you load a project from within VB, it probably won't work(as the current path is wrong, and the DLL won't be found unless it's in the system directory).

  16. #16
    Frenzied Member ae_jester's Avatar
    Join Date
    Jun 2001
    Location
    Kitchener Ontario Canada Earth
    Posts
    1,545
    I'm not sure why registering the DLL doesnt work. I've tried that before and failed. But it seems to work as long as you have it in the directory where your app is running, so thats what I always do.

  17. #17

    Thread Starter
    Registered User
    Join Date
    Jul 2001
    Location
    israel
    Posts
    81
    First of all Thank u !!
    Now i use 100 for compression and i dont get a good quality,what is the best compression ?
    even when i put 10000 i get bad quality so i don't understand how the compression works.
    Last edited by asi; Jun 10th, 2004 at 01:49 AM.

  18. #18
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654
    The scale is 0 - 100

  19. #19
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573
    Originally posted by ae_jester
    I've attached a Bmp2Jpeg DLL which I use in many projects to convert images between bmp and jpg. Works great!
    [/Highlight]
    Can this dll be used in reverse mode, i.e., jpg 2 bmp? Just curious.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  20. #20
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573
    Originally posted by DiGiTaIErRoR
    Right... if you load a project from within VB, it probably won't work(as the current path is wrong, and the DLL won't be found unless it's in the system directory).
    I've had the same problem trying to use this dll, sometimes it works, sometimes it doesn't. I start the project from its own folder where I have placed the dll. I don't understand why it wouldn't work at times.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  21. #21
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Help!!!

    I reference the dll by the string
    app.path & "\Bmp2Jpeg.sll"
    and I get this message: file Bmp2Jpeg.dll not found. But IT IS there, in the project folder.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  22. #22
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654
    Have you checked what App.Path is?

  23. #23
    Frenzied Member ae_jester's Avatar
    Join Date
    Jun 2001
    Location
    Kitchener Ontario Canada Earth
    Posts
    1,545
    I hope this is a typo!

    VB Code:
    1. app.path & "\Bmp2Jpeg.sll"

    Might want to try dll at the end

  24. #24
    Frenzied Member ae_jester's Avatar
    Join Date
    Jun 2001
    Location
    Kitchener Ontario Canada Earth
    Posts
    1,545
    I've had the same problem trying to use this dll, sometimes it works, sometimes it doesn't. I start the project from its own folder where I have placed the dll. I don't understand why it wouldn't work at times.
    Always works for me!

  25. #25
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573
    [QUOTE]Originally posted by ae_jester
    [B]I hope this is a typo!

    VB Code:
    1. app.path & "\Bmp2Jpeg.sll"

    It is...
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  26. #26
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573
    Originally posted by Merri
    Have you checked what App.Path is?
    Yes, it's correct.
    I have 2 folders in the desktop, each for a different project. For one of them it works but not for the other...!!!!????
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  27. #27
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654
    Urgh, just place the DLL to system or system32 folder and you get no problems.

  28. #28
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573
    Also I've tried Dir(app.path & "\Bmp2Jpeg.dll") and it returns an empty string indicating not found.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  29. #29
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573
    Originally posted by Merri
    Urgh, just place the DLL to system or system32 folder and you get no problems.
    Yes it does work this way but I still don't see why it works sometimes in the app.path and sometimes it doesn't. I have reasons why I'd rather have the dll in the app folder.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  30. #30
    Lively Member jkmcgrath's Avatar
    Join Date
    Dec 2004
    Posts
    79

    Re: Making Picture With VB

    Thanks! This is just what I needed and works like a champ

    Quote Originally Posted by ae_jester
    I've attached a Bmp2Jpeg DLL which I use in many projects to convert images between bmp and jpg. Works great!

    To use it:

    VB Code:
    1. Private Declare Function BmpToJpeg Lib "Bmp2Jpeg.dll" _
    2.     (ByVal bmpFileName As String, ByVal JpegFilename As String, _
    3.      ByVal CompressQuality As Integer) As Integer
    4.  
    5. 'To convert an image
    6. Call BmpToJpeg(strBmpFileName, strJpgFileName, 100) 'the last parameter is the picture quality (compression)
    Just an infant in VB years

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