Hi
I have below code . I want that from Original Picture. I want to display from centre of the bottom and 40 percent height from Bottom
I am writing code in VB6
Below is the code
Dim lSourceX As Long, lSourceY As Long
Dim lOldWidth As Long, lOldHeight As Long
Dim lNewWidth As Long, lNewHeight As Long
Picture1.Picture = LoadPicture(App.Path & "\O_" & tno & ".jpg")
' -=[ 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
Thanks
Sangeetha SPosted Mar 21, 2025, 5:43 AM
To modify your code so that the image is displayed from the center of the bottom and 40% height from the bottom, you can adjust the calculations for
lSourceYandlNewHeight. Here's how you can do it:Eliana BlakePosted Mar 20, 2025, 3:59 PM
From your code snippet, it seems like you are trying to crop an image in VB6. The provided code calculates the dimensions for cropping an image from the center of the bottom, keeping 40% of the image's height from the bottom.
Here's a breakdown of the code logic:
1. Load the original image named as "O_tno.jpg" into Picture1.
2. Convert the image dimensions from twips to pixels.
3. Calculate the new width and height, which are 70% of the original width and height, respectively.
4. Determine the coordinates (lSourceX, lSourceY) for the top left corner of the cropped area. In this case, it calculates the position from which to crop the image from the center of the bottom.
5. Resize the destination picture (Picture2) based on the new dimensions calculated.
6. Finally, perform the cropping using the BitBlt function from Picture1 to Picture2 while considering the calculated dimensions and starting coordinates.
This code effectively crops an image from the center of the bottom at 40% of its height. You can customize this further by adjusting the percentage values or the cropping logic based on your specific requirements.
If you need additional assistance or further customization, feel free to ask!