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




Reply With Quote