Picturebox (loadpicture with an offset)
I am using the following line of code:
Code:
pic1.Picture = LoadPicture("C:\test\OUTPUT.BMP")
...This works good. But now the image's height I'm loading is too high. The important part of the picture is then partially or entirely invisible in my picturebox (too low).
I don't want to change the dimension of the picturebox, and I don't want to edit the images.
Would there be a way to load the picture with an offset setting? I tried to play with LoadPicture parameters but it didn't seem to help.
Thanks for any solution.
Re: Picturebox (loadpicture with an offset)
Create an invisible picturebox, then load your image into it. Then you can use the PaintPicture, to simply paint the content partially, to the pic1 control.
Or, you can place an another picturebox, inside pic1, so you load the picture into the inner picbox, that is you can resize, then move the the negative position, so it will simply show you the content you are after.
Re: Picturebox (loadpicture with an offset)
Your paintpicture idea was the best as I didn't want to use additional pictureboxes on the form (even invisible) and I didn't need it 'aesthetic' at all neither.
Also, and I forgot to mention, the offset needed is static. I don't need to evalute the picture and move it accordingly.
That did it:
Code:
pic1.PaintPicture pic1.Picture, 0, -30
Thank you.
Re: Picturebox (loadpicture with an offset)
Why don't you use a scrollbar ;) ?
Check out this link...
http://www.vbforums.com/showthread.php?t=557689
Re: Picturebox (loadpicture with an offset)
Here is a way without using an additional control. It will proportionally scale the loaded picture to the size of your picturebox. This uses the .Render method of the stdPicture object.
Code:
Private Sub Command1_Click()
Dim tPic As StdPicture
Dim xRatio As Single, yRatio As Single
Dim dstCX As Long, dstCY As Long
Dim srcCX As Long, srcCY As Long
On Error Resume Next
Set tPic = LoadPicture(strFileName) ' supply valid path/filename
If Err Then
Err.Clear
Exit Sub
End If
On Error Goto 0
With Picture1
.Cls
.AutoRedraw = True
dstCX = .ScaleX(.ScaleWidth, .ScaleMode, vbPixels) ' convert picbox size to pixels
dstCY = .ScaleY(.ScaleHeight, .ScaleMode, vbPixels)
End With
With tPic
srcCX = Picture1.ScaleX(.Width, vbHimetric, vbPixels) ' convert stdPic size to pixels
srcCY = Picture1.ScaleY(.Height, vbHimetric, vbPixels)
xRatio = dstCX / srcCX
yRatio = dstCY / srcCY
If yRatio < xRatio Then xRatio = yRatio
dstCX = srcCX * xRatio
dstCY = srcCY * xRatio
' Draw to scale. Don't remove the +0& below else errors
.Render Picture1.hDC, 0&, 0&, dstCX + 0&, dstCY + 0&, _
0&, .Height, .Width, -.Height, ByVal 0&
End With
Picture1.Refresh
End Sub
Re: Picturebox (loadpicture with an offset)
See my previous reply also. In that reply I offered a way to scale the image to your picturebox, but you wanted to offset it, so with slight modifications of the previous post, we have the following
Code:
Private Sub LoadAndOffset(FileName As String, Destination As VB.PictureBox, xOffset As Long, yOffset As Long)
Dim tPic As StdPicture
Dim srcCX As Long, srcCY As Long
On Error Resume Next
Set tPic = LoadPicture(FileName)
If Err Then
Err.Clear
Exit Sub
End If
On Error Goto 0
With Destination ' the .Cls & .AutoRedraw can be done outside of this routine if desired; does not have to be done here
.Cls
.AutoRedraw = True
End With
With tPic
srcCX = Destination.ScaleX(.Width, vbHimetric, vbPixels)
srcCY = Destination.ScaleY(.Height, vbHimetric, vbPixels)
' Draw to scale. Don't remove the +0& below else errors
.Render Destination.hDC, xOffset + 0&, yOffset + 0&, srcCX + 0&, srcCY + 0&, _
0&, .Height, .Width, -.Height, ByVal 0&
End With
Destination.Refresh 'this can be called outside of this routine; does not need to be done here
End Sub
Edited: The +/- offsets must be passed as pixels.