By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,874 Members | 1,027 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,874 IT Pros & Developers. It's quick & easy.

can i change the size of a file dynamically

P: n/a
can i change the size of a file dynamically ?
for example have 100 Kb and i want to decrease it to 20 Kb
thanks

Jan 26 '07 #1
Share this Question
Share on Google+
8 Replies


P: n/a
What file do you mean?
<mi********@gmail.comwrote in message
news:11*********************@k78g2000cwa.googlegro ups.com...
can i change the size of a file dynamically ?
for example have 100 Kb and i want to decrease it to 20 Kb
thanks

Jan 26 '07 #2

P: n/a
System.IO.FileStream.SetLength()

Mike.

"Alexey Smirnov" <al************@gmail.comwrote in message
news:OD**************@TK2MSFTNGP05.phx.gbl...
What file do you mean?
<mi********@gmail.comwrote in message
news:11*********************@k78g2000cwa.googlegro ups.com...
>can i change the size of a file dynamically ?
for example have 100 Kb and i want to decrease it to 20 Kb
thanks


Jan 26 '07 #3

P: n/a

Alexey Smirnov :
What file do you mean?
<mi********@gmail.comwrote in message
news:11*********************@k78g2000cwa.googlegro ups.com...
can i change the size of a file dynamically ?
for example have 100 Kb and i want to decrease it to 20 Kb
thanks
oh sorry alexy i forgot
image file
jpg or gif
thanks for reply

Jan 26 '07 #4

P: n/a

Michael D. Ober :
System.IO.FileStream.SetLength()

Mike.

"Alexey Smirnov" <al************@gmail.comwrote in message
news:OD**************@TK2MSFTNGP05.phx.gbl...
What file do you mean?
<mi********@gmail.comwrote in message
news:11*********************@k78g2000cwa.googlegro ups.com...
can i change the size of a file dynamically ?
for example have 100 Kb and i want to decrease it to 20 Kb
thanks
thanks mike
is it for image file ?
i am a little amateur about image
can i change an image file size when it will shown by image control
may the main image file size have no change and only in image control
is decreased
thanks

Jan 26 '07 #5

P: n/a
Do you mean you want to resize an image dynamically (make its width and
height smaller)?
Or you want to change a quality/resolution of your image (decrease the
number of colors)?

Look at this
http://www.google.com/search?hl=en&q...+image+asp.net

On Jan 26, 10:03 pm, "miladha...@gmail.com" <miladha...@gmail.com>
wrote:
Michael D. Ober :
System.IO.FileStream.SetLength()
Mike.
"Alexey Smirnov" <alexey.smir...@gmail.comwrote in message
news:OD**************@TK2MSFTNGP05.phx.gbl...
What file do you mean?
<miladha...@gmail.comwrote in message
>news:11*********************@k78g2000cwa.googlegr oups.com...
>can i change the size of a file dynamically ?
>for example have 100 Kb and i want to decrease it to 20 Kb
>thanksthanks mike
is it for image file ?
i am a little amateur about image
can i change an image file size when it will shown by image control
may the main image file size have no change and only in image control
is decreased
thanks- Hide quoted text -- Show quoted text -
Jan 27 '07 #6

P: n/a

Alexey Smirnov نوشته است:
Do you mean you want to resize an image dynamically (make its width and
height smaller)?
Or you want to change a quality/resolution of your image (decrease the
number of colors)?

Look at this
http://www.google.com/search?hl=en&q...+image+asp.net

On Jan 26, 10:03 pm, "miladha...@gmail.com" <miladha...@gmail.com>
wrote:
Michael D. Ober äæÔÊå ÇÓÊ:
System.IO.FileStream.SetLength()
Mike.
"Alexey Smirnov" <alexey.smir...@gmail.comwrote in message
>news:OD**************@TK2MSFTNGP05.phx.gbl...
What file do you mean?
<miladha...@gmail.comwrote in message
news:11*********************@k78g2000cwa.googlegro ups.com...
can i change the size of a file dynamically ?
for example have 100 Kb and i want to decrease it to 20 Kb
thanksthanks mike
is it for image file ?
i am a little amateur about image
can i change an image file size when it will shown by image control
may the main image file size have no change and only in image control
is decreased
thanks- Hide quoted text -- Show quoted text -
i want to change the quality
i can change the height and and width of it but the file size is same
100KB=100KB
:)
may you help me please?
thanks

Jan 27 '07 #7

P: n/a
<miladha...@gmail.comwrote in message
>news:11*********************@k78g2000cwa.googlegr oups.com...
>can i change the size of a file dynamically ?
>for example have 100 Kb and i want to decrease it to 20 Kb
>thanksthanks mike
is it for image file ?
i am a little amateur about image
can i change an image file size when it will shown by image control
may the main image file size have no change and only in image control
is decreased
thanks- Hide quoted text -- Show quoted text -i want to change the quality
i can change the height and and width of it but the file size is same
100KB=100KB
You should check EncoderParameters Class (System.Drawing.Imaging),
which you can use when you create a new image.

You need to create a new Bitmap from the original image and set all
parameters you need. There is no way to set the size of the file of
target Bitmap and you have to play with resolution and quality
settings.

Sample code (VB):

Dim SourceBitmap As Drawing.Bitmap = New Bitmap(imageSrc)
Dim TargetBitmap As Drawing.Bitmap = New Bitmap(imageHeight,
imageWidth)

' To set resolution 72 dpi

Const res As Single = 72
TargetBitmap.SetResolution(res, res)

Dim objGraphics As Drawing.Graphics = Graphics.FromImage(TargetBitmap)

Dim objEncoder As Imaging.EncoderParameters

objGraphics.CompositingQuality = Drawing2D.CompositingQuality.Default
objGraphics.InterpolationMode =
Drawing2D.InterpolationMode.HighQualityBicubic

' Take a look MSDN for CompositingQuality and InterpolationMode -
there are many other settings

Dim recCompression As Rectangle = New Rectangle(0, 0, imageHeight,
imageWidth)
objGraphics.DrawImage(objSourceBitmap, recCompression)

objEncoder = New Imaging.EncoderParameters(2)

' Tell it to be "Encoder.Quality" with the desired iJPGQuality
objEncoder.Param(0) = New
Imaging.EncoderParameter(Imaging.Encoder.Quality, 85) ' 100 - quality
0..100
objEncoder.Param(1) = New
Imaging.EncoderParameter(Imaging.Encoder.Compressi on,
Imaging.EncoderValue.ColorTypeCMYK) ' 100 - quality 0..100

I would also recommend to look for more samples

http://www.google.com/search?hl=en&q...oderParameters

etc.

Jan 28 '07 #8

P: n/a
oh my goodness
very good
i don't forget you my friend
i will go to test it
thanks alot alexey

Jan 28 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.