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
Printable View
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
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....
here's a code that converts pictures into jpg...
use StretchBlt so set your height and width
forgot to attach...
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?
in my program you can see this code:
VB Code:
Private Sub Command1_Click() Dim i As Long For i = 0 To File1.ListCount - 1 'start loop File1.ListIndex = i 'set current file Picture1.Picture = LoadPicture(Dir1.Path & "\" & File1.FileName) 'load picture JPG.Create Picture1.ScaleWidth, Picture1.ScaleHeight 'create empty jpeg with correct size BitBlt JPG.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, Picture1.hdc, 0, 0, vbSrcCopy 'blit pic into empty jpeg SaveJPG JPG, Dir1.Path & "\" & Mid(File1.FileName, 1, Len(File1.FileName) - 3) & "jpg", Slider1.Value 'save jpeg Next 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:
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
You'll also have to add in the two extra stretchblt parameters.
:eek:Holy!!!!!! YESSSSSSS!!! :D
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)
:p :p :p
Sastraxi, thanks to you too, actually i got it already.....
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...
ok thanks cyborg ,