Hi
In below code i want to save img variable. Below is the code
VB.NET
Dim img As StdPicture
Set img = LoadPicture(App.Path & "O" & TrNo & Format(Date, "ddmmyyyy") & ".jpg") ' Load your image here
Dim lSourceX As Long, lSourceY As Long
Dim lOldWidth As Long, lOldHeight As Long
Dim lNewWidth As Long, lNewHeight As Long
lOldWidth = Picture1.ScaleWidth \ Screen.TwipsPerPixelX
lOldHeight = Picture1.ScaleHeight \ Screen.TwipsPerPixelY
lNewWidth = lOldWidth * 0.7
lNewHeight = lOldHeight * 0.7
lSourceX = (lOldWidth - lNewWidth) \ 2
lSourceY = (lOldHeight - lNewHeight) \ 2
img.Width = img.Width - img.ScaleWidth + (lNewWidth * Screen.TwipsPerPixelX)
img.Height = img.Height - img.ScaleHeight + (lNewHeight * Screen.TwipsPerPixelY)Thanks

Emily FosterRank #3,495 · 415 reputationPosted Mar 20, 2025, 5:59 AM EDT
Based on the given code snippet, it seems like you are loading an image file into a variable `img` using Visual Basic. The code snippet is adjusting the dimensions of the loaded image (`img`) by resizing it based on certain calculations.
If you want to save the `img` variable back to a file after the resizing operations have been performed, you would typically need to use a method to save the image. However, in Visual Basic using the `StdPicture` data type, there isn't a direct method to save the image back to a file.
One common approach to save the image would involve using external libraries or APIs that support image manipulation and saving, or converting the `img` variable to a different image format that can be saved using native Visual Basic functionality.
Here is a generic example of how you might approach saving the image using an alternative approach:
Private Sub SaveImageToFile(img As StdPicture, filename As String) Dim bmp As Object Set bmp = CreateObject("WIA.ImageFile") ' Convert StdPicture to BMP image bmp.LoadPicture img ' Save the BMP image to file bmp.SaveFile filename End Sub ' Usage: SaveImageToFile img, App.Path & "NewImage.jpg"In this example, the `SaveImageToFile` subroutine converts the `StdPicture` to a BMP image using the Windows Imaging Acquisition (WIA) library and then saves it to a specified file path. Remember to adjust the code above based on your specific requirements and environment.
Since direct saving of an `StdPicture` object may not be natively supported in Visual Basic, leveraging external libraries or custom functions like the example above can help achieve the desired outcome.
Sangeetha SRank #212 · 11.4K reputationPosted Mar 21, 2025, 1:10 AM EDT
Using Visual Basic 6.0 (VB6), and you want to save the
StdPictureobjectimgto a file after resizing it. VB6 doesn't have a direct built-in method to save aStdPictureto a file. You'll need to use a workaround, typically by:StdPictureto a PictureBox.Imageproperty to a file.Here's how you can modify your VB6 code to achieve this:
VB.Net
Dim img As StdPicture Set img = LoadPicture(App.Path & "O" & TrNo & Format(Date, "ddmmyyyy") & ".jpg") ' Load your image here Dim lSourceX As Long, lSourceY As Long Dim lOldWidth As Long, lOldHeight As Long Dim lNewWidth As Long, lNewHeight As Long lOldWidth = Picture1.ScaleWidth \ Screen.TwipsPerPixelX lOldHeight = Picture1.ScaleHeight \ Screen.TwipsPerPixelY lNewWidth = lOldWidth * 0.7 lNewHeight = lOldHeight * 0.7 lSourceX = (lOldWidth - lNewWidth) \ 2 lSourceY = (lOldHeight - lNewHeight) \ 2 ' Resize the image within the StdPicture object (as you've already done) img.Width = img.Width - img.ScaleWidth + (lNewWidth * Screen.TwipsPerPixelX) img.Height = img.Height - img.ScaleHeight + (lNewHeight * Screen.TwipsPerPixelY) ' Create a temporary PictureBox to render the image Dim tempPic As PictureBox Set tempPic = Controls.Add("VB.PictureBox", "tempPic") ' Set the PictureBox's AutoRedraw property to True tempPic.AutoRedraw = True ' Set the PictureBox's size to the desired new dimensions tempPic.Width = lNewWidth * Screen.TwipsPerPixelX tempPic.Height = lNewHeight * Screen.TwipsPerPixelY ' Draw the resized image onto the PictureBox tempPic.PaintPicture img, 0, 0, tempPic.Width, tempPic.Height, 0, 0, img.Width, img.Height ' Save the PictureBox's Image to a file SavePicture tempPic.Image, App.Path & "Resized_" & TrNo & Format(Date, "ddmmyyyy") & ".jpg" ' Remove the temporary PictureBox Controls.Remove "tempPic" Set tempPic = Nothing Set img = Nothing ' Release the StdPicture object