PDA

Click to See Complete Forum and Search --> : Resize bitmap with PaintPicture


Sezna
Mar 1st, 2001, 11:30 PM
I decided to make a thumbnailer as my VB learning project, add HTML skillz to that and it comes out pretty good. I am stuck however, on a fairly simple task - resizing a bitmap. There is a gazillion ways of doing this of course, but I can't use one properly. I first tried to use PictureClip and it worked, but the quality was horrible. Now I switched to PaintPicture, which works well but I can't get the output size right.

I load an image into the source picture box, then scale the image to the desired, say, height, and then scale the width accordingly (or the other way), and everything is perfect. When I analize the final height and width variables, they are what they should be, but when I do

picDest.PaintPicture picSrc.Picture, 0, 0, PicHeight, PicWidth

The resulting image dimensions are different from PicHeight and PicWidth (usually smaller)

Any way I can fix that? Or is there another way, without using two pic boxes and their huge overhead?

Thanks

kedaman
Mar 2nd, 2001, 03:13 AM
paintpicture syntax is:
object.PaintPicture picture, x1, y1, width1, height1, x2, y2, width2, height2, opcode
by omiting parameters for target size, how could you expect it to resize at all? If you want to leave the source dimensions as they are, you could omit them.
Paintpicture can be used with forms/pictureboxes picture properties, Stretchblt is available for blitting between dc's if you want to keep a lower resource usage.

Sezna
Mar 2nd, 2001, 09:03 AM
I am in awe of my own stupidity - simply variable manipulation and it works.

I can resize like that. Height1 and Width1 are the target size, everything else can be left out. The funny thing is, the result is still 3 pixels less, so I had to add those to the formula. I will look into StretchBlt, I think I have a demo of it somewhere, and it's much faster than Paint.

kedaman
Mar 2nd, 2001, 09:20 AM
funny thing is, that Paintpicture is faster ;) Note that scalemode determines what units are is used, that is independently for source and target, that's not probably the problem, if you picturebox has a border and you use the width/height instead of scalewidth/scaleheight then you could get this error.