[RESOLVED] Picture Flipping problem
I have a sub in a module for flipping pictures.
It normally works fine.
But I've added it to a project where it isn't working.
I tried copying the problem picturebox to a new project and it will work then.
The problem project is way too big to post here.
Any ideas on what could prevent the following sub from working?
VB Code:
Public Sub FlipImage(PicFrom As Object, picTo As Object)
'to place the new image over the old one just use the same obj for both paramiters
Dim bAuto As Boolean
Dim lScaleT As Long
Dim lScaleF As Long
On Error GoTo BadObject:
lScaleT = picTo.ScaleMode
picTo.ScaleMode = vbTwips
lScaleF = PicFrom.ScaleMode
PicFrom.ScaleMode = vbTwips
bAuto = picTo.AutoRedraw
picTo.AutoRedraw = True
picTo.PaintPicture PicFrom.Picture, 0, PicFrom.Height, _
PicFrom.Width, -PicFrom.Height
picTo.Picture = picTo.Image
picTo.AutoRedraw = bAuto
picTo.ScaleMode = lScaleT
PicFrom.ScaleMode = lScaleF
BadObject:
End Sub
Re: Picture Flipping problem
To find out why it isn't working, you need to know what the error is.. rather than simply ignoring it as you are doing. I realise that it is a useful thing to do for a 'live' application, but it stops you from finding problems when debugging.
Remove (or comment out) the On Error line so that you see the error message, and the line that causes the problem.
Re: Picture Flipping problem
Thx Si,
I tried REM'ing it, but there's no error.
It's just not flipping the image from this app.
The trap is just there in case someone throws a textbox or something at it :)
Re: Picture Flipping problem
So why have the parameters declared as Object, instead of as PictureBox?
The problem may be that the source PictureBox does not have AutoRedraw on.. in which case changing PicFrom.Picture to PicFrom.Image may solve it.
If not, you will need to step thru the code making sure that all the values (PicFrom.Width, etc) are appropriate.
Re: Picture Flipping problem
In case some other object with a picture was sent to it., like an imagebox
Re: Picture Flipping problem
Quote:
Originally Posted by si_the_geek
The problem may be that the source PictureBox does not have AutoRedraw on.. in which case changing PicFrom.Picture to PicFrom.Image may solve it.
Just tried changing it to....
VB Code:
picTo.PaintPicture PicFrom.Image, 0, PicFrom.Height, _
PicFrom.Width, -PicFrom.Height
Still no luck.
Quote:
Originally Posted by si_the_geek
If not, you will need to step thru the code making sure that all the values (PicFrom.Width, etc) are appropriate.
I think it is some kind of scaling problem.
I've noticed that it sometimes sets some huge 'pixels', depending on the background image.
But I don't undersatnd how it can be the problem in this case.
I'm using the same picturebox in both paramiters.
VB Code:
FlipImage picText, picText
Re: Picture Flipping problem
I've just realised another issue, which your latest problem is a symptom of.. you are using PicFrom.Height/Width (which are measured in the Form's scale), whereas you should be using the Scale versions (eg: PicFrom.ScaleHeight) which are the internal dimensions (so the same as the picture that is shown) measured in the ScaleMode of the control itself.
Re: Picture Flipping problem
Try using ScaleWidth and ScaleHeight instead of Width and Height
VB Code:
picTo.PaintPicture PicFrom.Image, 0, PicFrom.ScaleHeight, _
PicFrom.ScaleWidth, -PicFrom.ScaleHeight
Edit: i'm late :D
Re: Picture Flipping problem
Thx guys,just tried it, still no joy:(
Ok, I've taken just the parts of the program needed to re-create the problem and am uploading the project.
Basically it's capturing the portion of the image below picBlended and using two more pictureboxes to add text to it.
You can drag and drop picBlended to different areas and hit the 'Go' button again to re-blend the images.
The actual program does more, but this is enough to show the problem.
ALSO, I don't know why, but 'Sub SetSize()' doesn't get the scaling right the 1st time.
But after the second time it's called it works fine, so you'll have to clcick the button twice on the 1st try.
Any ideas what's happening there?
------------
just removed the incomplete project
Re: Picture Flipping problem
modRotateImage is not included, FlipImage sub is there?
1 Attachment(s)
Re: Picture Flipping problem
Quote:
Originally Posted by jcis
modRotateImage is not included, FlipImage sub is there?
Oups, here it is with the module.
I also added a second button and pic box to show that it works.
But I had to remove the ScaleHeight and ScaleWidth.
For some reason they broke it.
Re: Picture Flipping problem
Getting stranger.
I didn't do much to the MirrorImage sub.
It doesn't work if you only checkmark it.
But if you checkmark 'Flip' and 'Mirror' it will mirror but not flip the text image.
Re: Picture Flipping problem
The problem with SetSize is again due to Height being in the ScaleMode of the parent, which in this case is picMain (and gets changed in CapBackground). The way to deal with this is to get the size in the correct scale, which you can do using ScaleX and ScaleY, eg:
VB Code:
lHght = Me.ScaleX(picText.TextHeight(sText), picText.ScaleMode, picMain.ScaleMode)
In FlipImage you need to have the Scale versions (with .Picture), otherwise (despite what you think) it doesn't work. If you use the non-scale versions, only a tiny square in the corner (which is the size you specified) gets modified.
As you are flipping it twice you can't see the actual problem - which is that the text is getting erased. To see this either step thu the code, or add a MsgBox before and after the calls to FlipImage (in SetText).
I'm afraid I can't remember right now how to persist drawn items (such as text) on a picturebox.. and have to go out soon.
Re: Picture Flipping problem
That got it!
I didn't think about the parent.
All that was needed to keep the text was..
VB Code:
picText.Print sText
picText.Picture = picText.Image
Re: [RESOLVED] Picture Flipping problem
Ah yes, silly me.. I should have remembered that one!
Quote:
Originally Posted by longwolf (deleted!)
I't looks like I can also pull all that scale swapping I was doing in the subs too.
You never need to swap ScaleMode - as you can ask for values in the scale you want by using ScaleX and ScaleY, eg:
VB Code:
picTo.PaintPicture PicFrom.Picture, 0, PicFrom.ScaleY(PicFrom.ScaleHeight, PicFrom.ScaleMode, picTo.ScaleMode), _
PicFrom.ScaleX(PicFrom.ScaleWidth, PicFrom.ScaleMode, picTo.ScaleMode), -PicFrom.ScaleY(PicFrom.ScaleHeight, PicFrom.ScaleMode, picTo.ScaleMode)
'or:
With PicFrom
picTo.PaintPicture .Picture, 0, .ScaleY(.ScaleHeight, .ScaleMode, picTo.ScaleMode), _
.ScaleX(.ScaleWidth, .ScaleMode, picTo.ScaleMode), -.ScaleY(.ScaleHeight, .ScaleMode, picTo.ScaleMode)
End With
Many objects (Form, PictureBox, Printer, ...) support the ScaleX/ScaleY methods.
Re: [RESOLVED] Picture Flipping problem
Quote:
Originally Posted by si_the_geek
Ah yes, silly me.. I should have remembered that one!
You never need to swap ScaleMode - as you can ask for values in the scale you want by using ScaleX and ScaleY, eg:
WOW, you typed a mouthful :)
Thx again.
But I do think you have to change to vbPixels for several of the API methods.
Re: [RESOLVED] Picture Flipping problem
Well actually you dont have to change scalemode, because you can specify the scale (instead of getting it from ScaleMode), eg:
VB Code:
PicFrom.ScaleY(PicFrom.ScaleHeight, picFrom.ScaleMode, vbPixels)
..but sometimes it is more efficient to temporarily swap scales (if you need to specify several values).