2
Answers

Crop Image

Ramco Ramco

Ramco Ramco

1w
53
1

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

Answers (2)