Hi
How to convert the below code in Module. Code is in VB6
Private Sub Image_Crop()
Dim lSourceX As Long, lSourceY As Long
Dim lOldWidth As Long, lOldHeight As Long
Dim lNewWidth As Long, lNewHeight As Long
' -=[ Convert to Pixels ]=-
lOldWidth = Picture1.ScaleWidth \ Screen.TwipsPerPixelX
lOldHeight = Picture1.ScaleHeight \ Screen.TwipsPerPixelY
' -=[ Calculate 70% of Width and Height ]=-
lNewWidth = lOldWidth * 0.7
lNewHeight = lOldHeight * 0.7
' -=[ Calculate Top Left of centered image ]=-
lSourceX = (lOldWidth - lNewWidth) \ 2
lSourceY = (lOldHeight - lNewHeight) \ 2
' -=[ Resize Destination Picture ]=-
Picture2.Width = Picture2.Width - Picture2.ScaleWidth + (lNewWidth * Screen.TwipsPerPixelX)
Picture2.Height = Picture2.Height - Picture2.ScaleHeight + (lNewHeight * Screen.TwipsPerPixelY)
' -=[ Crop Image ]=-
BitBlt Picture2.hDC, 0&, 0&, lNewWidth, lNewHeight, Picture1.hDC, lSourceX, lSourceY, SRCCOPY
' -=[ VB Equivalent: Values not converted to pixels ]=-
'Picture2.PaintPicture Picture1.Picture, 0, 0, lNewWidth, lNewHeight, lSourceX, lSourceY
Picture2.Refresh
End Sub
Thanks
Ramco RamcoPosted Mar 19, 2025, 1:30 PM
Hi
Where Picture1 & Picture2 to be declared/Created.
Thanks
Eliana BlakePosted Mar 19, 2025, 12:52 PM
To convert the provided code into a Module in VB6, you need to do the following:
1. Create a new Module in your VB6 project.
2. Copy the entire content of the `Image_Crop` subroutine from your form code and paste it into the new Module.
3. Adjust the references to Picture1 and Picture2 to ensure they are accessible from the Module.
Below is an example of how you can modify the code to work within a Module:
Remember to ensure that the necessary Picture1 and Picture2 objects are accessible from the Module for this code to work correctly. By moving this code into a Module, you can call the `Image_Crop` subroutine from different parts of your project without duplicating the code. Let me know if you need further assistance or have any other questions!