Results 1 to 11 of 11

Thread: saving images

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2001
    Posts
    52

    Unhappy saving images

    Hi all,

    I need to save any image file ( *.bmp /*.jpg or gif file) as a jpg.
    How to do it?

    If not ,how do i add a compression to it?



    I want to Reducxe the size of the image?

    Can this be done without using any dlls or ocx?


    Regards,
    Laxmi
    lxs

  2. #2
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    plenderj posted some code recently on how to resize

    i think you have to check www.planet-source-code.com for conversion examples

    hope it helps some

  3. #3
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527

  4. #4

    Thread Starter
    Member
    Join Date
    Feb 2001
    Posts
    52
    Thanks da_silvy . Actually i do know the savepicture ...
    But what i want to know is how to reduce the size of the image.
    Like if i choose a bitmap file of 1k the jpg image ( output of my program) has to be of a smaller size.
    Can you help me?
    Thanks again.

    Regards,
    lxs

  5. #5

    Thread Starter
    Member
    Join Date
    Feb 2001
    Posts
    52
    Hi da_silvy,

    Thanks for the site . I knew about it but your Keyword made a great diffrence to the answers i received.



    Regards,
    lxs

  6. #6
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    Originally posted by lxs
    Thanks da_silvy . Actually i do know the savepicture ...
    But what i want to know is how to reduce the size of the image.
    Like if i choose a bitmap file of 1k the jpg image ( output of my program) has to be of a smaller size.
    Can you help me?
    Thanks again.

    Regards,
    -->

    http://www.vbforums.com/showthread.p...t=plenderleith

    Originally posted by plenderj
    To resize you just use StretchBlt.
    I've posted numerous examples on the forums. Here's one too ;

    VB Code:
    1. ' By Jamie Plenderleith
    2. ' [email][email protected][/email]
    3. '
    4. ' This code will stretch the 'background' picture of a form to the size of the form
    5. ' Change the picDc = GeneradeDC(..) line to point to an appropriate graphic
    6. '
    7.  
    8. Option Explicit
    9.  
    10. Private picDc As Long
    11. Private picWidth As Long
    12. Private picHeight As Long
    13. Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
    14. Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
    15. Private Declare Function LoadImage Lib "user32" Alias "LoadImageA" (ByVal hInst As Long, ByVal lpsz As String, ByVal un1 As Long, ByVal n1 As Long, ByVal n2 As Long, ByVal un2 As Long) As Long
    16. Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
    17. Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
    18. Private Declare Function StretchBlt Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long
    19.  
    20.  
    21. Public Function GenerateDC(FileName As String) As Long
    22.     Dim DC As Long, picTemp As IPictureDisp
    23.     DC = CreateCompatibleDC(0)
    24.     If DC < 1 Then
    25.         Exit Function
    26.     End If
    27.     Set picTemp = LoadPicture(FileName)
    28.     picWidth = ScaleX(picTemp.Width)
    29.     picHeight = ScaleY(picTemp.Height)
    30.     SelectObject DC, picTemp
    31.     DeleteObject picTemp
    32.     Set picTemp = Nothing
    33.     GenerateDC = DC
    34. End Function
    35.  
    36. Private Sub Form_Load()
    37.     ScaleMode = 3
    38.     picDc = GenerateDC("c:\jamie\barrk.bmp")
    39.     With Picture1
    40.         .AutoRedraw = True
    41.         .Move 0, 0, ScaleWidth, ScaleHeight
    42.         .ScaleMode = 3
    43.     End With
    44.     doStretch
    45. End Sub
    46.  
    47. Private Function doStretch()
    48.     Debug.Print StretchBlt(Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, picDc, 0, 0, picWidth, picHeight, vbSrcCopy)
    49.     Picture1.Refresh
    50. End Function
    51.  
    52. Private Sub Form_Resize()
    53.     Picture1.Move 0, 0, ScaleWidth, ScaleHeight
    54.     doStretch
    55. End Sub

  7. #7

    Thread Starter
    Member
    Join Date
    Feb 2001
    Posts
    52
    Hi,


    Thanks a lot!!! This was some help!



    Very nice of you .

    Regards,
    LXS
    lxs

  8. #8
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    no problems

  9. #9

    Thread Starter
    Member
    Join Date
    Feb 2001
    Posts
    52
    Da_sily , You wont believe this. I made a program and the image that comes out of the above code is a bit not clear-slightly blured.
    My boss is not happy-says he wanted a quality similar to the the photo editor jpeg conversions!!!!

    Looks like a nightmare come true!


    Is there a way i can get good qquality image /improve the resolution of the image?

    Thanks and sorry to trouble again.

    You've been of great help .
    Regards,
    LXS
    lxs

  10. #10
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Microsoft's way is not necessarily the best remember!

    Add the following API declaration :
    VB Code:
    1. Declare Function SetStretchBltMode Lib "gdi32" Alias "SetStretchBltMode" (ByVal hdc As Long, ByVal nStretchMode As Long) As Long

    with the following constants

    VB Code:
    1. Const BLACKONWHITE = 1
    2. Const WHITEONBLACK = 2
    3. Const COLORONCOLOR = 3
    4. Const HALFTONE = 4

    Now, before you do any stretching, try calling SetStretchBltlMode on the Picturebox in question, and pass one of the four above constants in as the second parameter. Experiment with them to see which gives the best results.

    If that isn't good enough, then you'll have to write your own stretching routines (www.planetsourcecode.com might be of use here) or get a 3rd party control.
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  11. #11

    Thread Starter
    Member
    Join Date
    Feb 2001
    Posts
    52
    your code is great.
    Please see attached file.
    I wanted something like this...the problem is its too time consuming and large images dont fit in picture box..
    Thanks ,
    Regards,
    lxs

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