Image is scaled but why?

Maddock

Member
Joined
Sep 30, 2008
Messages
7
Programming Experience
1-3
Hello,

I have a bmp file which is 1728 X 1003 in size. I have some code that extracys only the protion of the bmp file I am interested in like this

VB.NET:
Dim g As Graphics

b = New Bitmap(680, 1000)

g = Graphics.FromImage(b)

' fill the background with white

g.FillRectangle(Brushes.White, New Rectangle(0, 0, 680, 1000))

' rectangle  to extract the portions required portion

Dim srcRect As New RectangleF(0, 0, 680, 1000)

' s is a string to the file

g.DrawImage(Image.FromFile(s), 30, 0, srcRect, GraphicsUnit.Pixel)

' display image

Me.PictureBox1.Image = b

'and save it to file in string t
           
Me.PictureBox1.Image.Save(t, System.Drawing.Imaging.ImageFormat.Bmp)

Now when I look at the original image in Paint I see the coordinates I need which is where I got the size 680 X 1000 from.

The picturebox displays exactly the correct portion.

But when I open the saved file the extracted portion is reduced in size to 356 X 483 and the rest of the image is white for a total size of 680 X 1000.

Can anyone explain to me why the image gets reduced please?

This happens even if I do b.save(t)
 
Possibly to do with the unit of measure that the srcRect parameter uses. It must use a default of the System.Drawing.GraphicsUnit enumeration. There is an overloaded member of the DrawImage method that allows this to be set.
 
Hello,

I looked carefully at this and saw the use of RectangleF so changed that to just Rectangle and then passed another rectangle in the x, y positions paramaters after the image 's'

after teaking the numbers I got what I needed apart from not really understanging how it works.
 
Back
Top