can i change the size of a file dynamically

Discussion in 'ASP .Net' started by miladhatam@gmail.com, Jan 26, 2007.

  1. Guest

    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, 2007
    #1
    1. Advertising

  2. What file do you mean?


    <> wrote in message
    news:...
    > can i change the size of a file dynamically ?
    > for example have 100 Kb and i want to decrease it to 20 Kb
    > thanks
    >
     
    Alexey Smirnov, Jan 26, 2007
    #2
    1. Advertising

  3. System.IO.FileStream.SetLength()

    Mike.

    "Alexey Smirnov" <> wrote in message
    news:...
    > What file do you mean?
    >
    >
    > <> wrote in message
    > news:...
    >> can i change the size of a file dynamically ?
    >> for example have 100 Kb and i want to decrease it to 20 Kb
    >> thanks
    >>

    >
    >
     
    Michael D. Ober, Jan 26, 2007
    #3
  4. Guest

    Alexey Smirnov äæÔÊå ÇÓÊ:
    > What file do you mean?
    >
    >
    > <> wrote in message
    > news:...
    > > 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, 2007
    #4
  5. Guest

    Michael D. Ober äæÔÊå ÇÓÊ:
    > System.IO.FileStream.SetLength()
    >
    > Mike.
    >
    > "Alexey Smirnov" <> wrote in message
    > news:...
    > > What file do you mean?
    > >
    > >
    > > <> wrote in message
    > > news:...
    > >> 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, 2007
    #5
  6. 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=resize image asp.net



    On Jan 26, 10:03 pm, "" <>
    wrote:
    > Michael D. Ober äæÔÊå ÇÓÊ:
    >
    >
    >
    > > System.IO.FileStream.SetLength()

    >
    > > Mike.

    >
    > > "Alexey Smirnov" <> wrote in message
    > >news:...
    > > > What file do you mean?

    >
    > > > <> wrote in message
    > > >news:...
    > > >> 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 -
     
    Alexey Smirnov, Jan 27, 2007
    #6
  7. Guest

    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=resize image asp.net
    >
    >
    >
    > On Jan 26, 10:03 pm, "" <>
    > wrote:
    > > Michael D. Ober äæÔÊå ÇÓÊ:
    > >
    > >
    > >
    > > > System.IO.FileStream.SetLength()

    > >
    > > > Mike.

    > >
    > > > "Alexey Smirnov" <> wrote in message
    > > >news:...
    > > > > What file do you mean?

    > >
    > > > > <> wrote in message
    > > > >news:...
    > > > >> 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, 2007
    #7
  8. > > > > > <> wrote in message
    > > > > >news:...
    > > > > >> 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.Compression,
    Imaging.EncoderValue.ColorTypeCMYK) ' 100 - quality 0..100

    I would also recommend to look for more samples

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

    etc.
     
    Alexey Smirnov, Jan 28, 2007
    #8
  9. Guest

    oh my goodness
    very good
    i don't forget you my friend
    i will go to test it
    thanks alot alexey
     
    , Jan 28, 2007
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. tiewknvc9
    Replies:
    6
    Views:
    672
    Chris Uppal
    Oct 1, 2006
  2. Replies:
    2
    Views:
    279
  3. Wongod
    Replies:
    2
    Views:
    727
  4. Jason Cavett

    Preferred Size, Minimum Size, Size

    Jason Cavett, May 23, 2008, in forum: Java
    Replies:
    5
    Views:
    12,643
    Michael Jung
    May 25, 2008
  5. JV
    Replies:
    0
    Views:
    221
Loading...

Share This Page