Amro Osama
asked on
Smooth picture Resizing ...(using Pixel sampling maybe)
Hey there ....
i need a way to resize Pictures .. but to resize them smoothly ... as all the methods i tried do the same .. like .paintpicture and stretchblt
so i heard i can resize a Picture using Pixel sampling or resampling .. donnow really ... this way it's resized with a smooth look...
So any help would be appreciated ...
OHDev
i need a way to resize Pictures .. but to resize them smoothly ... as all the methods i tried do the same .. like .paintpicture and stretchblt
so i heard i can resize a Picture using Pixel sampling or resampling .. donnow really ... this way it's resized with a smooth look...
So any help would be appreciated ...
OHDev
ASKER
Thank you very much for your help ..
but i already know this one ...
i would like something simpler ...or in other words this example makes you crazy because it contains so much codes and routines ...
so is there any simplier way ... or like
Public Function ResamplePic(Pic as stdpicture,XPixels as integer,YPixels as Integer) as StdPicture
'blabla code
'
'
end Function
Thank you
OHDev
but i already know this one ...
i would like something simpler ...or in other words this example makes you crazy because it contains so much codes and routines ...
so is there any simplier way ... or like
Public Function ResamplePic(Pic as stdpicture,XPixels as integer,YPixels as Integer) as StdPicture
'blabla code
'
'
end Function
Thank you
OHDev
Also at:
Resampling with Alpha
http://vbaccelerator.com/home/VB/Code/vbMedia/DIB_Sections/Resampling_With_Alpha/article.asp
I used this for resampling for my previous project and the result is good too, nah.. code may be a bit long too..
Resampling with Alpha
http://vbaccelerator.com/home/VB/Code/vbMedia/DIB_Sections/Resampling_With_Alpha/article.asp
I used this for resampling for my previous project and the result is good too, nah.. code may be a bit long too..
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Oh, if you need a Picture object of the result add this ...
'Paint the resampled picture to picture2
cDibSample.PaintPicture Picture2.hdc
Picture2.Refresh
Set Picture2.Picture = Picture2.Image '<<< Now you have a new picture object of the resampled image
'Paint the resampled picture to picture2
cDibSample.PaintPicture Picture2.hdc
Picture2.Refresh
Set Picture2.Picture = Picture2.Image '<<< Now you have a new picture object of the resampled image
hi OHDev2004
u can use image object instead of picture object , as images object has a property called stretch,,
when its false the the image will be resize itself to the size of the image the user has displayed..
u can use image object instead of picture object , as images object has a property called stretch,,
when its false the the image will be resize itself to the size of the image the user has displayed..
ASKER
-Thank you Erick37 for your great help ...
-and thank you ryancys for ur help but Erick's answer was more what i wanted .... i think they are kinda the same but the example which erick gave in the end was the right one :)
-thank you "any" but this wasn't what i wanted.
Erick37:
the code works OK ... but i have a small question ..
the resampling code is kinda Blurring the image when it resizes it .. right ?? .. isn't there a Value which i can change for that Blurring rate ??? .. i mean if it's too Blurry i can give it a small value so it's kinda close to the original ..
I don't know if you understood this or not ..
it should be something in the "ResampleDib" function .. i think it's a fixed value now .. so i need to know it to be able to specify the Blurring . Or "Smoothing" value ..
thanx a Lot for all of you
OHDev
-and thank you ryancys for ur help but Erick's answer was more what i wanted .... i think they are kinda the same but the example which erick gave in the end was the right one :)
-thank you "any" but this wasn't what i wanted.
Erick37:
the code works OK ... but i have a small question ..
the resampling code is kinda Blurring the image when it resizes it .. right ?? .. isn't there a Value which i can change for that Blurring rate ??? .. i mean if it's too Blurry i can give it a small value so it's kinda close to the original ..
I don't know if you understood this or not ..
it should be something in the "ResampleDib" function .. i think it's a fixed value now .. so i need to know it to be able to specify the Blurring . Or "Smoothing" value ..
thanx a Lot for all of you
OHDev
Hi OHDev
I took a look again at the code from VBAccelerator. What they do to resample the image is this:
1: Loop through each pixel position in the NEW image and find the corresponding pixel in the original image.
2: Read the original pixel and the pixel to the right, below, and below right.
3: Interpolate the 4 pixels in the x axis resulting in 2 pixels.
4: Interpolate the 2 newly interpolated pixels in the y axis leaving the final pixel to be written in the new image.
To illustrate:
X <- X
X <- X
Then
X
î
X
So, as you can see, there is not a way to set any parameters to control the sharpness of the resulting image. I think that the "blurring" effect is just a result of the scaling process. I notice it too when using IrfanView to rescale pictures. Sometimes I have to apply a sharpen filter to the picture to make it snap.
I took a look again at the code from VBAccelerator. What they do to resample the image is this:
1: Loop through each pixel position in the NEW image and find the corresponding pixel in the original image.
2: Read the original pixel and the pixel to the right, below, and below right.
3: Interpolate the 4 pixels in the x axis resulting in 2 pixels.
4: Interpolate the 2 newly interpolated pixels in the y axis leaving the final pixel to be written in the new image.
To illustrate:
X <- X
X <- X
Then
X
î
X
So, as you can see, there is not a way to set any parameters to control the sharpness of the resulting image. I think that the "blurring" effect is just a result of the scaling process. I notice it too when using IrfanView to rescale pictures. Sometimes I have to apply a sharpen filter to the picture to make it snap.
ASKER
:) ...
thank you a Lot for making this clear to me ..
LOL ... so the main thing i wanted to resample the resized image ... and that definitly must blur the image to make it smooth .. now i'll need to apply a SHarpen effect to it .. Funny isn't it ... LOL
naa .. it isn't that important .. it's good as it is now .. just kidding
Thank you a lot
OHDev
thank you a Lot for making this clear to me ..
LOL ... so the main thing i wanted to resample the resized image ... and that definitly must blur the image to make it smooth .. now i'll need to apply a SHarpen effect to it .. Funny isn't it ... LOL
naa .. it isn't that important .. it's good as it is now .. just kidding
Thank you a lot
OHDev
Hi I liked the code, but I got a question. I want the picture to resize to a specific value, like 640x480 or other. How can I set it? Thanks!
The Resample method is where you set the height and width (I believe it's in pixels)
Set cDibSample = cDib.Resample(Height, Width)
Set cDibSample = cDib.Resample(Height, Width)
ASKER
Erick37 is right ...
see the Accepted answer... it's an Excellent working method :)
OHDev
see the Accepted answer... it's an Excellent working method :)
OHDev
Ok perfect! This was an excellent code, and I want to say congratulations for Erick. Now I can do what I want to do! :)
ASKER
:) ... yeah Thank you Erick :)
Cheers
OHDev
Cheers
OHDev
"What you can do with this sample
Image Processing
Blurring and softening
Sharpening
Embossing
Customised filters
Minimum, Maximum and Average Rank filters for impressionistic effects
Colour Manipulation
Colourise images
Darken and Lighten images
Gray scale images
Floyd-Stucci Black and White conversion
Decrease colour depth by dithering and matching to a specified palette.
Image Combination
Add, subtract with offsets or take the darkest/lightest pixels
Resample Images
Demonstrating how to use interpolation to create a smooth resized version of an image."
Image Processing Using DIB Sections
http://vbaccelerator.com/home/VB/Code/vbMedia/Image_Processing/Image_Processing_Using_DIB_Sections/article.asp