Results 1 to 10 of 10

Thread: Image Stuff

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2001
    Location
    Australia
    Posts
    29

    Post Image Stuff

    Hi,

    Ive been searching numerous sites as well as here and havent found anything.

    I want to know how i can resize an image and save it in the new dimensions as well. Also maintaining some of the quality.

    ALso, how can i save images from a picture box as either a gif or jpeg, which currently arent supported

    Thanks
    mindpower interactive - myBBoard - netAMP - xJournal

  2. #2
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    You can use the BitBlt API of a picture, refresh said picture, and SavePicture the .Image property.

    Here's my tut on BitBlt:
    http://vbden.tripod.com/articles/invmask.htm

    To save Gifs and I believe JPEGs too, you can download controls from http://www.vbaccelerator.com/.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jan 2001
    Location
    Australia
    Posts
    29
    Thanks for the links

    while scanning through your tutorial i think noticed an eror

    VB Code:
    1. Function sCopy(SrcDC as Long, DstDC as Long, dW as Long, dH as Long, X as Long, Y as Long) as Long
    2.    sCopy = BitBlt(DstDC, X, Y, dW, dH, SrcDC, 0, 0, SRCCOPY
    3. End Function

    should be

    VB Code:
    1. Function sCopy(SrcDC as Long, DstDC as Long, dW as Long, dH as Long, X as Long, Y as Long) as Long
    2.    sCopy = BitBlt(DstDC, X, Y, dW, dH, SrcDC, 0, 0, SRCCOPY[b])[/b]
    3. End Function

    The change is outlined in bold....

    I dont fully understand it, so if you could provide me with some an example of how to resize the image i would be greatly appreciated

    Thanks for the response
    mindpower interactive - myBBoard - netAMP - xJournal

  4. #4
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Whoops sorry I made a mistake there! Two actually! I'm rewriting the tutorial in a bit so it won't matter, thanks for pointing that out though.

    Not in the code, but with what I told you... BitBlt doesn't stretch. StretchBlt is one of the sister APIs that I mentioned. It takes two other commands:

    StretchBlt Dest DC, X, Y, Width, Height, Source DC, X, Y, SourceWidth, SourceHeight, Raster Operation

    So for example, let's resize an image. Set the AutoSize to True and the ScaleMode to 3 - Pixels.

    Now, to resize this to say, 50% of the image in both directions, we'll use this code. By the way, make sure you have another picutrebox called FiftyPercent.
    VB Code:
    1. StretchBlt FiftyPercent.hDC, 0, 0, Original.ScaleWidth * 0.5, Original.ScaleHeight * 0.5, Original.hDC, 0, 0, Original.ScaleWidth, Original.ScaleHeight, vbSrcCopy
    2. FiftyPercent.Refresh
    3. SavePicture FiftyPercent.Image, "C:\Fifty Percent.bmp"
    That should all work out. It's a nasty looking resize but it does the job nonetheless.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jan 2001
    Location
    Australia
    Posts
    29
    oh ok, thanks for the help!

    I had a look through http://www.vbaccelerator.com/ but i only found something to save as JPEG and it also requires another dll or ocx...

    Right now im having a look through freevbcode and vbcode but arent having much luck, i am going to try planet source code after this. But if you know of anywhere else, can you please tell me, i cant think of anything else
    mindpower interactive - myBBoard - netAMP - xJournal

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Jan 2001
    Location
    Australia
    Posts
    29
    Also, what function (and the syntax for it) to i have to declare for StretchBlt (just the parameters for it).

    Thanks
    mindpower interactive - myBBoard - netAMP - xJournal

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Jan 2001
    Location
    Australia
    Posts
    29
    ok, i got it, but it wont work..

    here is what im using

    VB Code:
    1. Set Picture1.Picture = CaptureScreen()
    2.     StretchBlt picResized.hdc, 0, 0, picResized.ScaleWidth, picResized.ScaleHeight, Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, vbSrcCopy
    3.     picResized.Refresh

    Picture1 receives the screen capture correctly but when i do the StretchBlt stuff, it doesnt put it into picResized, and it stays blank

    lol, thanks for this
    mindpower interactive - myBBoard - netAMP - xJournal

  8. #8
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Take out the refresh, I dunno, let me fire up VB and give you some working code.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  9. #9
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Yeah, that's it, just take out the refresh and it'll work itself out. Dunno what I was thinking...
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  10. #10
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    I heavily modified a piece of code from Rod Stephen's Visual Basic Graphics Programming book that I have. I've also implemented StretchBlt so you can see the difference.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

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