I dont get this, when I resize an image, .NET modifies the image and "smooths" it. I dont want it to do so!
This is a small picture, resized with my app and with mspaint, see the difference:
I want my program to resize the image just like MS Paint would do it. Right now, when I resize the picturebox, .NET makes the image smooth or whatever, you can see. How can I do what mspaint does?
I tried the DrawImage class and I also tried to resize the image by setting the sizeMode to stretch. Both work the same way
help plz
Last edited by MrPolite; Sep 26th, 2002 at 03:30 PM.
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB ) VB.NET to C# conversion tips!!
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB ) VB.NET to C# conversion tips!!
Resizes the picture in the same way. Basically if I set the sizeMode to Stretch and then I just resize the picturebox, I get the exact same result.
Am I using your code correctly?
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB ) VB.NET to C# conversion tips!!
Originally posted by Aerials Hmm does it do the same when u make it larger?
well, the picturebox's size is getting bigger as I'm zooming in it. Just like you would zoom in a picture in mspaint, but here I'm getting a weird result
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB ) VB.NET to C# conversion tips!!
well, you can just simply set the SizeMode property of your picturebox to PictureBoxSizeMode.StretchImage and then just change the hight and width of the picturebox. I just dont like the way it resizes it.
If you do the above method, it wont resize the real image inside, it will just show the resized image. (for example if you save PictureBox.Image to a file, it will be saved with its original size and not with the resized size). If you want the REAL image inside the picturebox to be resized then you could do this:
VB Code:
Dim gr As Graphics = picBox.CreateGraphics()
Dim tmpImage As Image = picBox.Image
' Clear the image
gr.Clear(picBox.BackColor)
picBox.SizeMode = PictureBoxSizeMode.AutoSize
gr.DrawImage(tmpImage, 0, 0, newWidth, newHeight)
I'm not that good in VB.NET, so my way might not be the best way for this, but it works. (meh, you guys post your code if you know a better way)
umm and btw I havent tested that code
Now someone plz help ME!!
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB ) VB.NET to C# conversion tips!!
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB ) VB.NET to C# conversion tips!!
well, it sucks but there should be a way to do this correctly!!!!! (well, besides using an API)
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB ) VB.NET to C# conversion tips!!
Originally posted by Hu Flung Dung Alright. I'm making a game, in which I need the exact same functionality.
Here's what I'm using:
Dim imgImage1 as Image
Dim imgImage2 as Image
'Actually, I use the Bitmap object, but Bitmap is inherited from Image, so it works exactly the same
'Make imgImage1 = the graphic you want to stretch
'Make imgImage2 = a blank image of the same resolution you want to stretch imgImage1 to
Dim G as Graphics = Graphics.FromImage(imgImage2)
G.DrawImage(imgImage1, New Rectangle(0, 0, <your width>, <your height>))
Basically, the DrawImage function will re-draw imgImage1 on imgImage2 and stretch it to the boundaries of the specified Rectangle object.
Maybe I need to visit these forums more often.
well I've tried the DrawImage method, I dont think your code would result in anything different.... I'll try it though
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB ) VB.NET to C# conversion tips!!
nope, same problem
I didnt say I want to know how to resize an Image. My problem is that the image isnt resized correctly, the way I want it to be
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB ) VB.NET to C# conversion tips!!
Originally posted by DevGrp I think you reason why the resized image is being smoothed out is because it is being antialiased.
Try to play around with the antialiased property and see if that works.
Good luck
where can I find that?
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB ) VB.NET to C# conversion tips!!
Originally posted by DevGrp I'll try to figure something out when I get home.
BTW It would help if you posted some code for me to work with.
Later
umm same code that I posted before...
VB Code:
Dim gr As Graphics = picBox.CreateGraphics()
Dim tmpImage As Image = picBox.Image
gr.Clear(picBox.BackColor)
picBox.SizeMode = PictureBoxSizeMode.AutoSize
gr.DrawImage(tmpImage, 0, 0, newWidth, newHeight)
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB ) VB.NET to C# conversion tips!!
Hey, Sorry I took so long to reply. Anyway, I did'nt try the antialias mode with your code, because I needed more to work with. However I did try something else and It worked perfect. The code will resize and save the image to a format of your choice.
Source and program is attached.
It is in C# but I can convert it to VB.NET if you want.
hey DevGrp, thanks for your help but still the same problem
It DOES resize the image, so does my code.... but I'm still getting the same result: when the image is resized, it gets blury
and yes I know, this is not noticable if you have a picture of something and you are resizing it a little bit. But if you have a very small picture which is made of some basic lines, it's gunno look very ugly when you resize it (see the picture in the first post)
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB ) VB.NET to C# conversion tips!!
Did you use the code I posted? Because I tried my program with the pictures that you posted, and when I resize it, it comes out ok. Its not blurry. I increase and decrease the size and its not blurry.
Originally posted by DevGrp Did you use the code I posted? Because I tried my program with the pictures that you posted, and when I resize it, it comes out ok. Its not blurry. I increase and decrease the size and its not blurry.
yes I used your code.... the original picture that I used is this :
and the RESULT is the one that you see in the first post
try using this image and try resizing it to something like 500x500 pixels and you'll see that it gets blury
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB ) VB.NET to C# conversion tips!!
Originally posted by DevGrp I'll see what I can do.
I was trying to avoid any APIs, because they THINK .NET can do EVERYTHING, but sounds like it's not always true.....
tnx for your help I hope you can find a way
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB ) VB.NET to C# conversion tips!!
I think the problem is because .net is 'resampling' the picture to increase the size, whereas in paint you are just zooming into a view and all it does is show you an enlarged view of the pixels.
To remdy this you need to build your own resampling routine that will iterate throught the image you wish to resize and build a new image based on the pixel information.
So say for example your original image is 2 pixels wide by 2 pxels deep as below:
Code:
ox
xo
x = black pixel
o = white pxel
Then you would have a loop something like
Code:
For x = 1 to 2
for y = 1 to 2
if pixel(x,y) = black then
draw a black box in new image
else
draw a white box in new image
end if.
next y
next x
This is greatly simplyfied but say you are wanting to zoom in 500% then you are aming to draw a new image that looks like the following:
ie: you are examining each pixel in the original image and drawing a larger version of it (based on the scaling factor) in the new image.
I imagine the resizing code behind the .net picture box is doing just this but that it has an antialiasing/resampling procedure built in. I doubt that you can switch this off so the only way to do what you want is to do it manually as above.
Initially it is probably a lot more work to get the thing implemented but if you stick it in a procedure you would be able to use it anywhere.
Thanks Slaine making a function of my own would be a little hard I guess or rather SLOW
also I want a function that will change the picture's size to the specified height and width (stretch the picture).... making a function like this is kinda hard...
So how should I use an API in .NET? I guess I should stick with bitblt/stretchblt
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB ) VB.NET to C# conversion tips!!
Here is some C# code you can convert. I use this code to scale images to fit in the viewing area of my app so you can see the whole picture. It seems to do a good job. Maybe it will work for you. Other than something like this...I don't know what to tell you.
Code:
private void ScaleImageToFit(string filename)
{
// This will take in a file path, figure out the available view
// area, then make the passed in picture fit that area.
Bitmap pic = new Bitmap(filename);
// Get the size of the pic.
SizeF sizef = new SizeF(pic.Width / pic.HorizontalResolution, pic.Height / pic.VerticalResolution);
// Figure out the scale based on orientation of the pic.
float fScale = Math.Min(viewArea.Width / sizef.Width, viewArea.Height / sizef.Height);
// Subtract from the scale so the scroll bars don't appear.
fScale -= 0.2f;
// Get the size of the image after scale.
sizef.Width *= fScale;
sizef.Height *= fScale;
// Set the size of the view area.
viewAreaPic.Width = (int)sizef.Width;
viewAreaPic.Height = (int)sizef.Height;
// Let the pic fill the view area since it is now resized
// to the proper size.
viewAreaPic.Image = pic;
}
Originally posted by hellswraith You may also want to pass this hint in to the Graphics object with your code:
g.SmoothingMode = SmoothingMode.HighQuality
There are a few other smoothing modes. My guess is you probably want high quality, not antialiased.
Good luck.
THANK YOU!!!!
Finally it worked!I didnt think there is a way to change these stuff! aaah what a fool I am!!!
this did the work:
gr.InterpolationMode = InterpolationMode.NearestNeighbor
thanks again!
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB ) VB.NET to C# conversion tips!!
Originally posted by hellswraith Welcome. Every time I read this post I didn't realize what you were asking. Sorry I didn't get you pointed in that direction from the beginning.
oh well, my english is quite messed up. It's hard to explain
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB ) VB.NET to C# conversion tips!!
aah I had another problem! if anyone wants to do this, remember to do this too:
gr.PixelOffsetMode = PixelOffsetMode.Half
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB ) VB.NET to C# conversion tips!!