Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cropping and resizing jpegs in vb6 1

Status
Not open for further replies.

tedsmith

Programmer
Nov 23, 2000
1,762
AU
Just returned from a fantastic 15,000km camper trailer trip of Central and West Australia outback I have 3 hrs HD video and 3000 jpegs taken by the wife to integrate into a "home video"
In order for the Adobe video editor to cope with so many HD stills, I have to pre crop each jpeg from 3x4 rectangular, 2816 x 2122 pixel to 16x9 widescreen and save as a 1900 x 1080 pixel jpeg.
I also need to resize or zoom in on some of the pictures to reframe or eliminate unwanted objects.

I normally use Photoshop to do this but it is extremely time consuming. All other apps I have seen require you to do a lot of keyboard entry and fiddling because they expect you to retain the same aspect ratio.

Sometimes it is quicker to use Paint but this requires calculating and entering the % reduction to get the required pixel size.

I would like to be able to simply select the jpeg to a wide screen frame, expand the pic inside the frame with the mouse and shift horizontally or vertically until I have it the best and save to the fixed 1900x1080 pixels with one click.

What would be the best way to make a vb6 app that I can crop and re-size jpgs and always save in a set pixel result without affecting the picture size?

I can simulate this easily manipulating an image box inside a smaller frame but how do I convert the visible result to a jpeg of fixed pixel resolution?

 
Or approx 50-60 lines of code

Sorry, but the question here wasn't "is there an application that can do this", but "can I do this in VB" - even after a certain amount of pushing concerning an applicatio the OP has that is MORE than capable of achieving this. And whilst in the end there are always alternatives to almost everything, this is still a VB6 forum.

I'm sorry if this offends anyone, but I have to say that I'm beginning to find it extrememly odd that certain erstwhile forum proponents of VB6 have now decided it is dead and buried, and use almost every opportunity to point people to use an alternative solution
 
Bravo strongm!

Here is my simple version using the keyboard and controls as mentioned earlier.
The majority of pics only need widening to the screen width and aligning the top and maybe a little more expanding.

Code:
Option Explicit
Dim Cmd As Boolean
Dim MyFileName As String

'Application to stretch, move and crop a graphic to same pixels as a HD movie frame.

Private Sub Form_Load()
Convert
End Sub


Private Sub Convert()
'Creates a cropped and/or magnified fixed pixel 1900x1080 picture
Dim file_name As String

Picture2.Picture = LoadPicture("")
DoEvents
' Resize the picture.
Picture2.AutoRedraw = True
Picture2.PaintPicture Picture1.Picture, _
        HPos.Value, VPos.Value, _
        PicSize.Value, PicSize.Value * (Aspect.Value / 100)
Picture2.Picture = Picture2.Image
TopValue.Caption = VPos.Value
HPosValue.Caption = HPos.Value
SizeValue.Caption = PicSize.Value
AspectValue.Caption = Aspect.Value
Image1.Picture = Picture2.Image 'preview it
Cmd = False
End Sub

Private Sub cmd16x9Top_Click()
'Standard top aligned conversion to 16x9
Cmd = True
HPos.Value = 0
VPos.Value = 0
PicSize.Value = 1900
Aspect.Value = 75
Convert
End Sub

Private Sub cmdDef16x9_Click()
'standard 16x9 centred
Cmd = True
HPos.Value = 0
VPos.Value = -150
PicSize.Value = 1900
Aspect.Value = 75
Convert
End Sub

Private Sub cmdDef3x4_Click()
'standard 3x4 centered
Cmd = True
HPos.Value = 240
VPos.Value = 0
PicSize.Value = 1440
Aspect.Value = 75
Convert
End Sub

Private Sub cmdlarger_Click()
'Zoom in
Form_KeyDown 107, 0
End Sub

Private Sub cmdsmaller_Click()
'zoom out
Form_KeyDown 109, 0
End Sub

Private Sub cmdStandardAspect_Click()
'restore to standard aspect ratio
Cmd = True
Aspect.Value = 75
Convert
End Sub

Private Sub Command1_Click()
'Load graphic
On Error GoTo NoPic
Cmd = True
CommonDialog1.ShowOpen
MyFileName = CommonDialog1.FileName
Picture1.Picture = LoadPicture(MyFileName)
cmdNextGraphic.Visible = True
Convert
EndLoad:
On Error GoTo 0
Exit Sub

NoPic:
Resume EndLoad
End Sub

Private Sub Command2_Click()
'Save the result.
If MyFileName > "" Then
    SavePicture Picture2.Picture, Left(MyFileName, Len(MyFileName) - 3) & "bmp"
Else
    MsgBox "No File Name selected"
End If
End Sub


Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
'shits size and image around with number +-5 pixels and pg keys +-25 pixels
Dim TempSize As Long
On Error GoTo Ignore
Cmd = True
Select Case KeyCode
Case 33
VPos.Value = VPos.Value - 25

Case 34
VPos.Value = VPos.Value + 25

Case 35
HPos.Value = HPos.Value + 25

Case 36
HPos.Value = HPos.Value - 25

Case 100
HPos.Value = HPos.Value - 5

Case 104
VPos.Value = VPos.Value - 5

Case 102
HPos.Value = HPos.Value + 5

Case 98
VPos.Value = VPos.Value + 5

Case 107, 187
'+
TempSize = PicSize.Value
PicSize.Value = PicSize.Value + 25
HPos.Value = HPos.Value + (TempSize - PicSize.Value) / 2

Case 109, 189
'-
TempSize = PicSize.Value
PicSize.Value = PicSize.Value - 25
HPos.Value = HPos.Value + (TempSize - PicSize.Value) / 2

Case 144
lblNumLock.Visible = False

End Select
Convert
On Error GoTo 0
Exit Sub

Ignore:
MsgBox Error, vbCritical, "Select a default centered button"
Resume Next
End Sub

Private Sub HPos_Change()
'H centering scrollbar
cmdClose.SetFocus
If Cmd = False Then Convert
End Sub

Private Sub PicSize_Change()
'H & V size
cmdClose.SetFocus
If Cmd = False Then Convert
End Sub

Private Sub Aspect_Change()
'Aspect ratio scrollbar
cmdClose.SetFocus
If Cmd = False Then Convert
End Sub

Private Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
'aligns pic centre to wherever the mouse pointer is
HPos.Value = (X * 2 - (PicSize * 7.5)) / 15
VPos.Value = (Y * 2 - (PicSize * (Aspect.Value / 100) * 7.5)) / 15
End Sub

Private Sub VPos_Change()
'V centering scrollbar
cmdClose.SetFocus
If Cmd = False Then Convert
End Sub

Private Sub cmdClose_Click()
Unload Form1
End
End Sub

Private Sub cmdClose_Click()
Unload Form1
End
End Sub
 
strongm
Could you please advise which form do you put which controls and what is the purpose of using an MDI form?
 
The picture boxes (the only controls) all go on Form1, sorry if that was not clear.

Using an MDI form this way automatically provides free, codeless scrolling the moment the MDI child form is bigger than the MDI parent form
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top