Results 1 to 10 of 10

Thread: How to compress according to width n Height?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2003
    Posts
    599

    How to compress according to width n Height?

    how to compress an image or picture into a specific width and heigth that i want???

    input = any image file (gif,bmp,jpg)
    Final outcome =*.jpg
    Thank You

  2. #2
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    If you want to save it as a JPG I think you have to read upon the JPG struct and make your own function. Not the easiest in the world, but it isn't impossible....

  3. #3
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    here's a code that converts pictures into jpg...
    use StretchBlt so set your height and width
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  4. #4
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    forgot to attach...
    Attached Files Attached Files
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2003
    Posts
    599

    Wink Cyborg

    OK Thank you Cyborg,

    This proggy is pretty cool. It does reduces the size of .bmp file when it is converted to .jpg file....

    But unfortunately it does not accept the jpg file for RE-Conversion.....

    Does that means that all files that are in JPG cannot be re-convert again???? because your proggy do not read in the jpg files..

    this is my case, i want to generate a thumbnail size picture of all sorts to satisfy my web page display speed....

    so i hope to re-convert the jpg(which most of my picture files are) to a smaller height and width........ How should i go about it??

    where can i get to know more on how the compression of pictures works?
    Thank You

  6. #6
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    in my program you can see this code:
    VB Code:
    1. Private Sub Command1_Click()
    2. Dim i As Long
    3.     For i = 0 To File1.ListCount - 1 'start loop
    4.    
    5.         File1.ListIndex = i 'set current file
    6.        
    7.         Picture1.Picture = LoadPicture(Dir1.Path & "\" & File1.FileName) 'load picture
    8.        
    9.         JPG.Create Picture1.ScaleWidth, Picture1.ScaleHeight 'create empty jpeg with correct size
    10.         BitBlt JPG.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, Picture1.hdc, 0, 0, vbSrcCopy 'blit pic into empty jpeg
    11.         SaveJPG JPG, Dir1.Path & "\" & Mid(File1.FileName, 1, Len(File1.FileName) - 3) & "jpg", Slider1.Value 'save jpeg
    12.     Next
    13. End Sub

    first it starts a loop to do all bmp files in the list (For i = 0 To File1.ListCount - 1)

    then it sets the current index of the loop to the file list to be able get the filename (File1.ListIndex = i)

    then it loads this picture into the picturebox (Picture1.Picture = LoadPicture(Dir1.Path & "\" & File1.FileName))

    then it creates an empty jpg, blit from the pixeturebox into it, then saves it with the selected compression.



    if you also want to be able to load jpg's you have to select the filelist...goto the property "Pattern", and change it from "*.bmp;*.gif" to "*.bmp;*.gif;*.jpg"

    to stretch it, you have to declare the StretchBlt API:
    VB Code:
    1. Private Declare Function StretchBlt Lib "gdi32" Alias "StretchBlt" (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

    then change this line:
    JPG.Create Picture1.ScaleWidth, Picture1.ScaleHeight
    to whatever new size you want.

    then change this line:
    BitBlt JPG.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, Picture1.hdc, 0, 0, vbSrcCopy
    to use StretchBlt instead
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  7. #7
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    You'll also have to add in the two extra stretchblt parameters.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2003
    Posts
    599

    Many Many Thanks

    Holy!!!!!! YESSSSSSS!!!

    Cyborg , i got it. it works really well and cool ........

    if you don't mind, i really would like to know more about all your declaration and its purposes.... especially those in the module....(as i am still stranger to all those declaration that you made)




    Sastraxi, thanks to you too, actually i got it already.....
    Thank You

  9. #9
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    im glad you could make it

    to be perfectly honest with you, im not the one who wrote the jpg compression code. maybe if you look closer into the code and read the comments, you'll understand it a bit. i have'nt read that code because im a total stranger to file handling and such things so i think i'll start with something easier first...
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2003
    Posts
    599
    ok thanks cyborg ,
    Thank You

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