Hi
In below code i want that Original Image should get cropped to fit in another Picture whose size is 3000 X 3000
VB.NET
Dim originalPic As PictureBox
Dim croppedPic As PictureBox
Set originalPic = Picture1 ' Set your source PictureBox
Set croppedPic = Picture2 ' Set your destination PictureBox
' Centre of the original image
Dim centerX As Long, centerY As Long
centerX = originalPic.ScaleWidth / 2
centerY = originalPic.ScaleHeight / 2Thanks

Daniel WrightRank #2,947 · 489 reputationPosted Mar 23, 2025, 1:57 AM EDT
Based on the provided code snippet, it seems like you are on the right track to crop an image in VB6. To crop the original image to fit into another Picture whose size is 3000 X 3000, you can use the following steps:
1. Determine the cropping dimensions based on the original image size and the desired size of the destination Picture.
2. Calculate the cropping coordinates to extract the desired portion of the original image.
3. Copy the cropped portion of the original image to the destination Picture.
Here is an example code snippet that you can use to crop the image:
Dim originalPic As PictureBox Dim croppedPic As PictureBox Set originalPic = Picture1 ' Set your source PictureBox Set croppedPic = Picture2 ' Set your destination PictureBox ' Centre of the original image Dim centerX As Long, centerY As Long centerX = originalPic.ScaleWidth / 2 centerY = originalPic.ScaleHeight / 2 ' Define the cropping dimensions Dim cropWidth As Long, cropHeight As Long cropWidth = If(originalPic.ScaleWidth > 3000, 3000, originalPic.ScaleWidth) cropHeight = If(originalPic.ScaleHeight > 3000, 3000, originalPic.ScaleHeight) ' Calculate the cropping coordinates Dim x As Long, y As Long x = centerX - (cropWidth / 2) y = centerY - (cropHeight / 2) ' Create a new bitmap to store the cropped image Dim croppedBmp As Bitmap Set croppedBmp = New Bitmap(cropWidth, cropHeight) ' Copy the cropped portion of the original image to the bitmap croppedBmp = originalPic.Picture.Clone(x, y, cropWidth, cropHeight) ' Display the cropped image in the destination PictureBox croppedPic.Picture = croppedBmpThis code snippet calculates the cropping dimensions based on the original image size and ensures that the cropped portion fits within a 3000 X 3000 frame. It then extracts the desired portion of the original image and displays it in the destination PictureBox.
Feel free to customize this code further based on your specific requirements or if you need additional functionality. Let me know if you have any more questions or need further assistance!
Muhammad Imran AnsariRank #326 · 7.6K reputationPosted Mar 23, 2025, 7:47 AM EDT
Hello Ramco,
To crop the original image so that it fits into another
PictureBoxwith a 3000 × 3000 size, you need to center the crop area and ensure a square selection. Below is the updated VB6 code to accomplish this:Dim originalPic As PictureBox Dim croppedPic As PictureBox Set originalPic = Picture1 ' Source PictureBox Set croppedPic = Picture2 ' Destination PictureBox (3000x3000) ' Set the crop size Dim cropSize As Long cropSize = 3000 ' We need a 3000x3000 square crop ' Find the center of the original image Dim centerX As Long, centerY As Long centerX = originalPic.ScaleWidth \ 2 centerY = originalPic.ScaleHeight \ 2 ' Calculate the top-left corner of the crop region Dim cropX As Long, cropY As Long cropX = centerX - (cropSize \ 2) cropY = centerY - (cropSize \ 2) ' Ensure the cropping doesn't exceed boundaries If cropX < 0 Then cropX = 0 If cropY < 0 Then cropY = 0 ' Resize the destination PictureBox croppedPic.Width = cropSize * Screen.TwipsPerPixelX croppedPic.Height = cropSize * Screen.TwipsPerPixelY ' Crop and copy the image BitBlt croppedPic.hDC, 0, 0, cropSize, cropSize, originalPic.hDC, cropX, cropY, SRCCOPY croppedPic.RefreshGood Luck!