PDA

Click to See Complete Forum and Search --> : Image Stuff


surfichris
Dec 29th, 2001, 10:54 PM
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 ;)

Sastraxi
Dec 29th, 2001, 11:03 PM
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/.

surfichris
Dec 29th, 2001, 11:17 PM
Thanks for the links

while scanning through your tutorial i think noticed an eror


Function sCopy(SrcDC as Long, DstDC as Long, dW as Long, dH as Long, X as Long, Y as Long) as Long
sCopy = BitBlt(DstDC, X, Y, dW, dH, SrcDC, 0, 0, SRCCOPY
End Function


should be


Function sCopy(SrcDC as Long, DstDC as Long, dW as Long, dH as Long, X as Long, Y as Long) as Long
sCopy = BitBlt(DstDC, X, Y, dW, dH, SrcDC, 0, 0, SRCCOPY)
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 :)

Sastraxi
Dec 29th, 2001, 11:28 PM
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.StretchBlt FiftyPercent.hDC, 0, 0, Original.ScaleWidth * 0.5, Original.ScaleHeight * 0.5, Original.hDC, 0, 0, Original.ScaleWidth, Original.ScaleHeight, vbSrcCopy
FiftyPercent.Refresh
SavePicture FiftyPercent.Image, "C:\Fifty Percent.bmp"That should all work out. It's a nasty looking resize but it does the job nonetheless.

surfichris
Dec 29th, 2001, 11:36 PM
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

surfichris
Dec 29th, 2001, 11:49 PM
Also, what function (and the syntax for it) to i have to declare for StretchBlt (just the parameters for it).

Thanks :cool:

surfichris
Dec 30th, 2001, 12:14 AM
ok, i got it, but it wont work..

here is what im using


Set Picture1.Picture = CaptureScreen()
StretchBlt picResized.hdc, 0, 0, picResized.ScaleWidth, picResized.ScaleHeight, Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, vbSrcCopy
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

Sastraxi
Dec 30th, 2001, 10:45 AM
Take out the refresh, I dunno, let me fire up VB and give you some working code.

Sastraxi
Dec 30th, 2001, 10:48 AM
Yeah, that's it, just take out the refresh and it'll work itself out. Dunno what I was thinking...

Sastraxi
Dec 30th, 2001, 11:31 AM
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.