|
-
Feb 19th, 2009, 09:33 PM
#1
Thread Starter
Hyperactive Member
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.
-
Feb 19th, 2009, 09:36 PM
#2
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.
-
Feb 19th, 2009, 09:54 PM
#3
Thread Starter
Hyperactive Member
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.
-
Feb 20th, 2009, 05:29 AM
#4
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
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Feb 20th, 2009, 10:38 AM
#5
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
Last edited by LaVolpe; Feb 20th, 2009 at 10:52 AM.
-
Feb 20th, 2009, 10:47 AM
#6
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.
Last edited by LaVolpe; Feb 20th, 2009 at 11:54 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|