Re: can i change the size of a file dynamically



<miladha...@xxxxxxxxx> wrote in message
news:1169831472.662817.48100@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
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.

.



Relevant Pages

  • Re: Accessing a linked file in a Word document using VBA
    ... defintiion in the header Gallery. ... Dim Pwd As String ' String variable to hold passwords for protected documents ... Dim pState As Boolean ' Document protection state flag ... > update the source image file and the new image would appear ...
    (microsoft.public.word.vba.general)
  • Re: Accessing a linked file in a Word document using VBA
    ... I have tried the macro you listed - but it does not prompt. ... defintiion in the header Gallery. ... Dim Pwd As String ' String variable to hold passwords for protected documents ... update the source image file and the new image would appear ...
    (microsoft.public.word.vba.general)
  • Re: Accessing a linked file in a Word document using VBA
    ... Dim Pwd As String ' String variable to hold passwords for protected documents ... Dim pState As Boolean ' Document protection state flag ... Place the code in your document's template, then activate the document to be updated and run the macro 'ChangePicLinks'. ... update the source image file and the new image would appear ...
    (microsoft.public.word.vba.general)
  • Re: image on form
    ... It is used when you select an image file in the properties ... Dim f As FileDialog ... To get help on the above, whack ctrl-g to get to the debug window. ...
    (microsoft.public.access.forms)
  • Re: can i change the size of a file dynamically
    ... Or you want to change a quality/resolution of your image (decrease the ... may the main image file size have no change and only in image control ...
    (microsoft.public.dotnet.framework.aspnet)