Hi
With this code it is displating image from centre of the right side. I want that it should displat the centre of Picture1 image.
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC 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 dwRop As Long) As Long
Const SRCCOPY = &HCC0020
Picture1.AutoRedraw = True
Picture1.Picture = LoadPicture(App.Path & "\O_" & tno & ".jpg")
Picture1.Width = Picture1.Picture.Width
Picture1.Height = Picture1.Picture.Height
Picture1.Picture = Picture1.Image
' -=[ Convert to Pixels ]=-
lOldWidth = Picture1.ScaleWidth \ Screen.TwipsPerPixelX
lOldHeight = Picture1.ScaleHeight \ Screen.TwipsPerPixelY
' -=[ Calculate 70% of Width and Height ]=-
lNewWidth = lOldWidth * 0.5
lNewHeight = lOldHeight * 0.5
' -=[ Calculate Top Left of centered image ]=-
lSourceX = (lOldWidth - lNewWidth) \ 2
lSourceY = (lOldHeight - lNewHeight) \ 2
Picture2.Width = Picture2.Width - Picture2.ScaleWidth + (lNewWidth * Screen.TwipsPerPixelX)
Picture2.Height = Picture2.Height - Picture2.ScaleHeight + (lNewHeight * Screen.TwipsPerPixelY)
BitBlt Picture2.hDC, 0&, 0&, lNewWidth, lNewHeight, Picture1.hDC, lSourceX, lSourceY, SRCCOPY
Thanks
Emily FosterPosted Mar 21, 2025, 12:53 AM
Hi! It seems like you're working on a piece of code to display an image centered within another image control. The code you provided uses the BitBlt function to perform a bit-block transfer of the image from Picture1 to Picture2 with the goal of centering it.
To address your concern about shifting the center of the displayed image from the right side to the center of the Picture1 image, you need to adjust the calculation for the source coordinates (lSourceX and lSourceY) to center the image based on Picture1's dimensions.
Here are the steps you can follow to achieve this:
1. Calculate the dimensions of Picture1 and adjust the source coordinates based on its dimensions.
2. Update the lSourceX and lSourceY calculations to center the image based on Picture1's size instead of lOldWidth and lOldHeight.
3. Ensure that lSourceX and lSourceY are calculated correctly to place the image at the center of Picture1 rather than the right side.
By making these adjustments, you can effectively display the image centered within Picture1. If you encounter any issues or need further assistance with the code, feel free to ask for more help or clarification. Happy coding!