Results 1 to 17 of 17

Thread: [RESOLVED] Picture Flipping problem

  1. #1

    Thread Starter
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    Resolved [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:
    1. Public Sub FlipImage(PicFrom As Object, picTo As Object)
    2. 'to place the new image over the old one just use the same obj for both paramiters
    3.     Dim bAuto As Boolean
    4.     Dim lScaleT As Long
    5.     Dim lScaleF As Long
    6.    
    7.     On Error GoTo BadObject:
    8.     lScaleT = picTo.ScaleMode
    9.     picTo.ScaleMode = vbTwips
    10.     lScaleF = PicFrom.ScaleMode
    11.     PicFrom.ScaleMode = vbTwips
    12.     bAuto = picTo.AutoRedraw
    13.     picTo.AutoRedraw = True
    14.     picTo.PaintPicture PicFrom.Picture, 0, PicFrom.Height, _
    15.                        PicFrom.Width, -PicFrom.Height
    16.     picTo.Picture = picTo.Image
    17.     picTo.AutoRedraw = bAuto
    18.     picTo.ScaleMode = lScaleT
    19.     PicFrom.ScaleMode = lScaleF
    20.    
    21. BadObject:
    22. End Sub

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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.

  3. #3

    Thread Starter
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    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

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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.

  5. #5

    Thread Starter
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    Re: Picture Flipping problem

    In case some other object with a picture was sent to it., like an imagebox

  6. #6

    Thread Starter
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    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:
    1. picTo.PaintPicture PicFrom.Image, 0, PicFrom.Height, _
    2.                        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:
    1. FlipImage picText, picText

  7. #7
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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.

  8. #8
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: Picture Flipping problem

    Try using ScaleWidth and ScaleHeight instead of Width and Height
    VB Code:
    1. picTo.PaintPicture PicFrom.Image, 0, PicFrom.ScaleHeight, _
    2.                        PicFrom.ScaleWidth, -PicFrom.ScaleHeight
    Edit: i'm late

  9. #9

    Thread Starter
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    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
    Last edited by longwolf; Jan 10th, 2007 at 02:56 PM.

  10. #10
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: Picture Flipping problem

    modRotateImage is not included, FlipImage sub is there?

  11. #11

    Thread Starter
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    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.
    Attached Files Attached Files

  12. #12

    Thread Starter
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    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.

  13. #13
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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:
    1. 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.

  14. #14

    Thread Starter
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    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:
    1. picText.Print sText
    2.     picText.Picture = picText.Image

  15. #15
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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:
    1. picTo.PaintPicture PicFrom.Picture, 0, PicFrom.ScaleY(PicFrom.ScaleHeight, PicFrom.ScaleMode, picTo.ScaleMode), _
    2.                        PicFrom.ScaleX(PicFrom.ScaleWidth, PicFrom.ScaleMode, picTo.ScaleMode), -PicFrom.ScaleY(PicFrom.ScaleHeight, PicFrom.ScaleMode, picTo.ScaleMode)
    3. 'or:
    4.     With PicFrom
    5.       picTo.PaintPicture .Picture, 0, .ScaleY(.ScaleHeight, .ScaleMode, picTo.ScaleMode), _
    6.                          .ScaleX(.ScaleWidth, .ScaleMode, picTo.ScaleMode), -.ScaleY(.ScaleHeight, .ScaleMode, picTo.ScaleMode)
    7.     End With
    Many objects (Form, PictureBox, Printer, ...) support the ScaleX/ScaleY methods.

  16. #16

    Thread Starter
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    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.

  17. #17
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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:
    1. PicFrom.ScaleY(PicFrom.ScaleHeight, picFrom.ScaleMode, vbPixels)
    ..but sometimes it is more efficient to temporarily swap scales (if you need to specify several values).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width