Results 1 to 17 of 17

Thread: [VB6] - stretch an image to usercontrol size

  1. #1

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,964

    [VB6] - stretch an image to usercontrol size

    i have 1 line for stretch 1 image in Usercontrol(by it size). but the width isn't correct
    Code:
    StretchBlt UserControl.hDC, 0, 0, UserControl.Width \ Screen.TwipsPerPixelX, UserControl.Height \ Screen.TwipsPerPixelY, PicAnimation(lngActualSubImage).hDC, 0, 0, PicAnimation(lngActualSubImage).Width, PicAnimation(lngActualSubImage).Height, vbSrcCopy
    (see the image for see the bug)
    what isn't correct?
    Attached Images Attached Images  
    VB6 2D Sprite control

    To live is difficult, but we do it.

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [VB6] - stretch an image to usercontrol size

    Your screen shot does not help exactly. We do not know what the source looks like.

    You are using PicAnimation(...).Width & PicAnimation(...).Height. Those measurements are in the scalemode of the container where the PicAnimation control resides. If not vbPixels, ensure you convert to pixels. If the PicAnimation controls have borders, suggest not using Width,Height but use ScaleWidth,ScaleHeight
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,964

    Re: [VB6] - stretch an image to usercontrol size

    Quote Originally Posted by LaVolpe View Post
    Your screen shot does not help exactly. We do not know what the source looks like.

    You are using PicAnimation(...).Width & PicAnimation(...).Height. Those measurements are in the scalemode of the container where the PicAnimation control resides. If not vbPixels, ensure you convert to pixels. If the PicAnimation controls have borders, suggest not using Width,Height but use ScaleWidth,ScaleHeight
    everything is in pixels, autoredraw is true and the border is none. and i try use the scale size, but the results are the same(except being big, is small. but tell me 1 thing if i use the control size(see the blue points), why the image have a diferent size?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  4. #4

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,964

    Re: [VB6] - stretch an image to usercontrol size

    for resulve the problem i use const values(like convert something):
    Code:
    StretchBlt UserControl.hDC, 0, 0, UserControl.ScaleWidth * (Screen.TwipsPerPixelX - 9), UserControl.ScaleHeight * (Screen.TwipsPerPixelY - 12), PicAnimation(lngActualSubImage).hDC, 0, 0, PicAnimation(lngActualSubImage).ScaleWidth, PicAnimation(lngActualSubImage).ScaleHeight, vbSrcCopy
    maybe using the last line(in 1st post) with these combination, the problem can be resolved
    but, please, tell me what you think.
    VB6 2D Sprite control

    To live is difficult, but we do it.

  5. #5
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [VB6] - stretch an image to usercontrol size

    I think it is not a good idea to hardcode some constants. You are not getting the correct result because of something else. To answer your question in post #3, I can't tell you unless you show us the source picturebox with the image in it.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  6. #6

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,964

    Re: [VB6] - stretch an image to usercontrol size

    Quote Originally Posted by LaVolpe View Post
    I think it is not a good idea to hardcode some constants. You are not getting the correct result because of something else. To answer your question in post #3, I can't tell you unless you show us the source picturebox with the image in it.
    ok.. heres i put the image in uc:
    Code:
    UserControl.Picture = PicAnimation(lngActualSubImage).Image
    the picanimation() is for recive the image\subtimage original. then i use the if's for do the effects:
    Code:
    If blnStretch = True Then
            StretchBlt UserControl.hDC, 0, 0, UserControl.ScaleWidth * (Screen.TwipsPerPixelX - 9), UserControl.ScaleHeight * (Screen.TwipsPerPixelY - 12), UserControl.hDC, 0, 0, PicAnimation(lngActualSubImage).ScaleWidth, PicAnimation(lngActualSubImage).ScaleHeight, vbSrcCopy
            UserControl.Picture = UserControl.Image
        End If
    but. like you said, can give some bad resultes... and i recive bad image results in some images
    what you need to know more?
    or i can put here a link(because i don't have space in my attachment file) and show you my work(entire project).. just say it
    VB6 2D Sprite control

    To live is difficult, but we do it.

  7. #7

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,964

    Re: [VB6] - stretch an image to usercontrol size

    i can show the image\subimage, without a problem, in autosize true(because without these effect the animation\static works normaly). my problem is try to sretch the image.
    VB6 2D Sprite control

    To live is difficult, but we do it.

  8. #8

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,964

    Re: [VB6] - stretch an image to usercontrol size

    1 big question: if my uc is in pixel and the form is in pixel, why the size is diferent?
    inside of uc: the width is 690;
    in form: the width is 46.
    now tell me something?
    (i debug these for see the results)
    or i must use the api function?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  9. #9
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [VB6] - stretch an image to usercontrol size

    UserControl.Width,Height are always in Twips: 690 in your case. Same as a form's Width,Height are always in Twips.
    UserControl.ScaleWidth,ScaleHeight are in usercontrol's ScaleMode: 46 in your case

    In post #2 above I tried to explain that to you. A control's Width,Height values are always in the control's container's scalemode. So UserControl1.Width will be in the uc's container's scalemode. UserControl1.Width is not the same as UserControl.Width called from within the uc.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  10. #10

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,964

    Re: [VB6] - stretch an image to usercontrol size

    Quote Originally Posted by LaVolpe View Post
    UserControl.Width,Height are always in Twips: 690 in your case. Same as a form's Width,Height are always in Twips.
    UserControl.ScaleWidth,ScaleHeight are in usercontrol's ScaleMode: 46 in your case

    In post #2 above I tried to explain that to you. A control's Width,Height values are always in the control's container's scalemode. So UserControl1.Width will be in the uc's container's scalemode. UserControl1.Width is not the same as UserControl.Width called from within the uc.
    ok. i understand that. but now i still have the same question: why that width(in these case) bug?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  11. #11

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,964

    Re: [VB6] - stretch an image to usercontrol size

    ......... i'm still blocked
    Last edited by joaquim; Nov 27th, 2010 at 11:17 AM.
    VB6 2D Sprite control

    To live is difficult, but we do it.

  12. #12

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,964

    Re: [VB6] - stretch an image to usercontrol size

    i'm good hehehehe
    i found the solution:
    1 - i have 1 picturebox for catch the real image size and works 100% fine;
    2 . i use the Extender object for catch the actual usercontrol size and works fine.
    Code:
    If blnStretch = True Then
            StretchBlt UserControl.hDC, 0, 0, Extender.Width, Extender.Height, UserControl.hDC, 0, 0, imgSize.Width, imgSize.Height, vbSrcCopy
            UserControl.Picture = UserControl.Image
        End If
    my little problem is if i reduze the original size(in UC) the image is showed like a double in diferent size. i belive that is something that i forget in that IF. can you advice me more?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  13. #13

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,964

    Re: [VB6] - stretch an image to usercontrol size

    ok... heres the code for avoid the double image:
    Code:
    If blnStretch = True Then
            picGraphicsEffects.Width = Extender.Width
            picGraphicsEffects.Height = Extender.Height
            picGraphicsEffects.Picture = Nothing
            StretchBlt picGraphicsEffects.hDC, 0, 0, Extender.Width, Extender.Height, UserControl.hDC, 0, 0, imgSize.Width, imgSize.Height, vbSrcCopy
            UserControl.Picture = Nothing
            picGraphicsEffects.Picture = picGraphicsEffects.Image
            UserControl.Picture = picGraphicsEffects.Image
        End If
    but when i reduse de image(from original size), i recive 1 bug. in image the half(more or less) image isn't showed. why? is about the stretchblt bug?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  14. #14
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [VB6] - stretch an image to usercontrol size

    There is no stretchblt bug I'm aware of. If you can show us a screenshot of the source picturebox with its image and then the result so we can better understand what the problem is, we might be able to offer more advice
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  15. #15

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,964

    Re: [VB6] - stretch an image to usercontrol size

    Quote Originally Posted by LaVolpe View Post
    There is no stretchblt bug I'm aware of. If you can show us a screenshot of the source picturebox with its image and then the result so we can better understand what the problem is, we might be able to offer more advice
    see the image. these bug only happens when the size is less than original
    Attached Images Attached Images  
    VB6 2D Sprite control

    To live is difficult, but we do it.

  16. #16
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [VB6] - stretch an image to usercontrol size

    If your source and destination picboxes are not the same size ratios then your image will appear to be stretched horizontally or vertically vs scaled. If your source picbox contains a bunch of blank space around the image, then the destination picbox will contain that extra space also when you StretchBlt.

    If you need to just blt the area around the source image, excluding any extra space, you will have to calculate a tight rectangle around the image and just StretchBlt that rectangle's dimensions.

    Regarding size ratios: If (sourceWidth/destWidth) <> (sourceHeight/destHeight) then you will not get a scaled rendering and you will have to determine what horizontal/vertical ratios to use.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  17. #17

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,964

    Re: [VB6] - stretch an image to usercontrol size

    Quote Originally Posted by LaVolpe View Post
    If your source and destination picboxes are not the same size ratios then your image will appear to be stretched horizontally or vertically vs scaled. If your source picbox contains a bunch of blank space around the image, then the destination picbox will contain that extra space also when you StretchBlt.

    If you need to just blt the area around the source image, excluding any extra space, you will have to calculate a tight rectangle around the image and just StretchBlt that rectangle's dimensions.

    Regarding size ratios: If (sourceWidth/destWidth) <> (sourceHeight/destHeight) then you will not get a scaled rendering and you will have to determine what horizontal/vertical ratios to use.
    sorry, but how can i resolve the problem?
    VB6 2D Sprite control

    To live is difficult, but we do it.

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