Page 1 of 2 12 LastLast
Results 1 to 40 of 57

Thread: Resizing/changing pic type

  1. #1

    Thread Starter
    Frenzied Member Blobby's Avatar
    Join Date
    Oct 2001
    Location
    England
    Posts
    1,512

    Resizing/changing pic type

    Does anyone know how to resize a pic and Save it as JPG (if it was a BMP)

    Many thanks
    There are 3 types of people in this world.........those that can count, and those that can't.

    Blobby

  2. #2
    Addicted Member chrisvl's Avatar
    Join Date
    Jul 2001
    Location
    Belgium - Somewhere between the bedroom and the toilet...or at work playing Oracle DBA :-)
    Posts
    233
    I can give code to resize the picture in a picturebox.

    But to store it as a jpeg, you will have to search on the web. I know there are add-ons that will do the job.

  3. #3
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    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
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  4. #4

    Thread Starter
    Frenzied Member Blobby's Avatar
    Join Date
    Oct 2001
    Location
    England
    Posts
    1,512
    Jamie/Chris

    Thanks. I want to point a control at a (JPG or BMP file) on disk and resize it so that it is lets say 400x400 instead of its original size, then save it as a JPG file. Ultimately changing a JPG or BMP file from 1024x768(for example) to 800x600 lets say. Not just resize for the screen but ACTUALLY resize the image.

    have you got any code that code do any of this?


    Blobby
    There are 3 types of people in this world.........those that can count, and those that can't.

    Blobby

  5. #5
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Search on www.planetsourcecode.com for code for working with JPEGs
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  6. #6
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    plenderleith ?



    hahahah

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

    blobby

    have a look at this thread

    http://www.vbforums.com/showthread.php?s=&postid=702615

  8. #8

    Thread Starter
    Frenzied Member Blobby's Avatar
    Join Date
    Oct 2001
    Location
    England
    Posts
    1,512
    da_Silvy.....What is your real name? I cant keep calling you that!

    Thanks for the info. Im a bit puzzled though.
    It doesnt really say what the outcome was as some people had problems doing it the way suggested. All I can find in search engines are ActiveX/DLL's that you have to pay 100 bucks for.
    It must be possible in that case so how come there is no code around to do it available for cut and paste?

    I still have little information on whether it is actually possible at all.


    Blob
    There are 3 types of people in this world.........those that can count, and those that can't.

    Blobby

  9. #9
    Addicted Member chrisvl's Avatar
    Join Date
    Jul 2001
    Location
    Belgium - Somewhere between the bedroom and the toilet...or at work playing Oracle DBA :-)
    Posts
    233
    I'm also very interested in this topic!

    I developed a thumbnail viewer.
    There is also a possibility to save the thumbs.
    This happens as BMP, which consumes a lot of disk space of course...

    I really wonder...is it possible to save as a jpeg?
    With an API or whatever?

    Christophe
    I do not have a specific statement...
    so I will use one of my wife

    Veni, Vidi, Visa ... I came, I saw, I shopped

  10. #10

    Thread Starter
    Frenzied Member Blobby's Avatar
    Join Date
    Oct 2001
    Location
    England
    Posts
    1,512
    Chris,

    Yes, I need to load a pic in either BMP or JPG format and RESIZE it to a specific size and then save it as JPG.

    I have searched the web for weeks and found NOTHING but DLL's you have to pay between 30 and 100 bucks for.

    There has to be someone who knows how to do this!

    If I find anything Ill let you know!
    There are 3 types of people in this world.........those that can count, and those that can't.

    Blobby

  11. #11
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    I'll post the code in a few minutes.
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  12. #12

    Thread Starter
    Frenzied Member Blobby's Avatar
    Join Date
    Oct 2001
    Location
    England
    Posts
    1,512
    Jamie if you can do this, you are a God!
    There are 3 types of people in this world.........those that can count, and those that can't.

    Blobby

  13. #13
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Putting the code together as we speak

  14. #14

    Thread Starter
    Frenzied Member Blobby's Avatar
    Join Date
    Oct 2001
    Location
    England
    Posts
    1,512
    Bet you cant do it really! :P
    There are 3 types of people in this world.........those that can count, and those that can't.

    Blobby

  15. #15
    Addicted Member chrisvl's Avatar
    Join Date
    Jul 2001
    Location
    Belgium - Somewhere between the bedroom and the toilet...or at work playing Oracle DBA :-)
    Posts
    233
    Hm, I found this link:

    http://www.planet-source-code.com/xq...s/ShowCode.htm

    It is a dll but it's free! I 'll give it a try, it looks good...
    I do not have a specific statement...
    so I will use one of my wife

    Veni, Vidi, Visa ... I came, I saw, I shopped

  16. #16

    Thread Starter
    Frenzied Member Blobby's Avatar
    Join Date
    Oct 2001
    Location
    England
    Posts
    1,512
    Chris,

    yes i saw it but it uses a DLL from Intel. I wanted to do it with no 3rd party controls
    There are 3 types of people in this world.........those that can count, and those that can't.

    Blobby

  17. #17
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Here ya go.
    Read instructions before use.

  18. #18

    Thread Starter
    Frenzied Member Blobby's Avatar
    Join Date
    Oct 2001
    Location
    England
    Posts
    1,512
    Cheers jamie, ill check it out!! Prepare for a big girly kiss!
    There are 3 types of people in this world.........those that can count, and those that can't.

    Blobby

  19. #19
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Big girly kiss ?
    'tis a brave man that gives me a kiss I can tell ya ...

  20. #20
    Addicted Member chrisvl's Avatar
    Join Date
    Jul 2001
    Location
    Belgium - Somewhere between the bedroom and the toilet...or at work playing Oracle DBA :-)
    Posts
    233
    But this uses also a third party OCX or what?
    I do not have a specific statement...
    so I will use one of my wife

    Veni, Vidi, Visa ... I came, I saw, I shopped

  21. #21
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Yes it does.
    I never said it didnt

  22. #22
    Addicted Member chrisvl's Avatar
    Join Date
    Jul 2001
    Location
    Belgium - Somewhere between the bedroom and the toilet...or at work playing Oracle DBA :-)
    Posts
    233
    Written in Delphi 4 with a memory leak and possibly a virus...
    If a believe all the user comments on the site...

    But I'll give it a try !

    Thanks for the help!
    I do not have a specific statement...
    so I will use one of my wife

    Veni, Vidi, Visa ... I came, I saw, I shopped

  23. #23
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    My virus scanner never said nothing about no virus.
    Anyway most of the people who post on planetsourcecode are absolute morons. I tested the jpg jobby here myself and it worked a dream.

  24. #24

    Thread Starter
    Frenzied Member Blobby's Avatar
    Join Date
    Oct 2001
    Location
    England
    Posts
    1,512
    Jamie,

    Yeah, Norton 2002 said nothing about a virus.
    Im not sure about the memory leak tho!
    There are 3 types of people in this world.........those that can count, and those that can't.

    Blobby

  25. #25
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    The only place a decent sized memory leak could be is in the GenerateDC function, and even thats not substantial (well not on mu laptop anyway).

    Some people were saying on psc that they'd use it to convert 500 images or so. So I wouldn't worry about it.

  26. #26
    Addicted Member chrisvl's Avatar
    Join Date
    Jul 2001
    Location
    Belgium - Somewhere between the bedroom and the toilet...or at work playing Oracle DBA :-)
    Posts
    233
    But it matters to me!!!

    I have to convert up to 10.000 images
    I do not have a specific statement...
    so I will use one of my wife

    Veni, Vidi, Visa ... I came, I saw, I shopped

  27. #27
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    It'll be grand.
    I can do a test if you'd like

  28. #28
    Addicted Member chrisvl's Avatar
    Join Date
    Jul 2001
    Location
    Belgium - Somewhere between the bedroom and the toilet...or at work playing Oracle DBA :-)
    Posts
    233
    That's very nice of you but I don't want to occupy your computer for a whole day

    10.000 images...count on +700 MB!
    I do not have a specific statement...
    so I will use one of my wife

    Veni, Vidi, Visa ... I came, I saw, I shopped

  29. #29
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    hang on.

  30. #30
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Bombed after about the 700th 33kb bitmap

  31. #31
    Addicted Member chrisvl's Avatar
    Join Date
    Jul 2001
    Location
    Belgium - Somewhere between the bedroom and the toilet...or at work playing Oracle DBA :-)
    Posts
    233
    Hm, Ok, so this is not a solution for me

    Perhaps I'll try that other dll I found...

    Thanks for testing!
    I do not have a specific statement...
    so I will use one of my wife

    Veni, Vidi, Visa ... I came, I saw, I shopped

  32. #32

    Thread Starter
    Frenzied Member Blobby's Avatar
    Join Date
    Oct 2001
    Location
    England
    Posts
    1,512
    I dont think the other link allows yu to resize the image. Only convert to JPG
    There are 3 types of people in this world.........those that can count, and those that can't.

    Blobby

  33. #33
    Addicted Member chrisvl's Avatar
    Join Date
    Jul 2001
    Location
    Belgium - Somewhere between the bedroom and the toilet...or at work playing Oracle DBA :-)
    Posts
    233
    True, but resizing is not a problem for me, that was already solved in a previous thread
    I do not have a specific statement...
    so I will use one of my wife

    Veni, Vidi, Visa ... I came, I saw, I shopped

  34. #34

    Thread Starter
    Frenzied Member Blobby's Avatar
    Join Date
    Oct 2001
    Location
    England
    Posts
    1,512
    A thought.

    If you use an Image control set to a small size and use the STRETCH property = True then load a large Image.........Does that shrinke the image internally too or just the display version of it. ie. Is the image still its original size if you resave it or is it only now as big as the shrunk imagebox image?

    In other words (if thats confusing) If you had an image box 100x100 on the screen set to Stretch=true and loaded a 1000x1000 image into it.....does it still contain the full image (1000x1000) if you resave the image1.Picture or is it now the reduced 100x100 picture that gets saved?
    Last edited by Blobby; Dec 17th, 2001 at 08:59 AM.
    There are 3 types of people in this world.........those that can count, and those that can't.

    Blobby

  35. #35
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    that'll stretch the imagebox, not the picture

  36. #36

    Thread Starter
    Frenzied Member Blobby's Avatar
    Join Date
    Oct 2001
    Location
    England
    Posts
    1,512
    Thats what i thought

    Ta.
    There are 3 types of people in this world.........those that can count, and those that can't.

    Blobby

  37. #37
    Addicted Member chrisvl's Avatar
    Join Date
    Jul 2001
    Location
    Belgium - Somewhere between the bedroom and the toilet...or at work playing Oracle DBA :-)
    Posts
    233
    I use this to resize a picture in a picturebox:

    Assume you have loaded a picture in a picturebox called picTmp.
    Be sure autoredraw is False!

    Now, set the width and height of the picturebox as you like:
    picTmp.height = ...
    picTmp.Width = ...

    Now use the following code:

    picTmp.AutoRedraw = True
    picTmp.PaintPicture picTmp, 0, 0, picTmp.Width, picTmp.Height

    Set picTmp = picTmp.Image
    picTmp.AutoRedraw = False


    This should do the trick.
    I do not have a specific statement...
    so I will use one of my wife

    Veni, Vidi, Visa ... I came, I saw, I shopped

  38. #38

    Thread Starter
    Frenzied Member Blobby's Avatar
    Join Date
    Oct 2001
    Location
    England
    Posts
    1,512
    Jamie, Ive tried your code bit the quality is.......well......not too good. The quality of the smaller picture looks nothing like the quality of the original. i was expecting it to be like VB when you load a 1024x768 image into a 400x300 picture box. The code gives quality similar to changing the colour depth to 256 colours.
    Is there any other way of resizing the image and keeping the quality ?
    There are 3 types of people in this world.........those that can count, and those that can't.

    Blobby

  39. #39
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    The only way to improve it is it use SetStretchBltMode() with HALFTONE

  40. #40

    Thread Starter
    Frenzied Member Blobby's Avatar
    Join Date
    Oct 2001
    Location
    England
    Posts
    1,512
    Blimey it gets complicated dont it?
    There are 3 types of people in this world.........those that can count, and those that can't.

    Blobby

Page 1 of 2 12 LastLast

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