Solved

Change Bitmap size

Posted on 2008-06-23
4
2,528 Views
Last Modified: 2011-09-20
Hello all,

I have created a bitmap and would like to change it's pixel size dimensions to 640x200
before I save it.
How would I do that?

Here is my code:

Dim screenshot As Bitmap = CType(data.GetData(GetType(System.Drawing.Bitmap)), Bitmap)
'Here the conversion should happen.
screenshot.Save("C:\" & imagename & ".jpg")

Also, could you please tell me how does the size in kb changes?

Thanks!
0
Comment
Question by:nectarios777
  • 2
4 Comments
 
LVL 47

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 125 total points
ID: 21850367
>>How would I do that?

Like this....

        Dim bmp As New Bitmap(640, 200)
        Dim g As Graphics = Graphics.FromImage(bmp)
        g.DrawImage(screenshot, 0, 0, bmp.Width, bmp.Height)
        bmp.Save("C:\" & imagename & ".jpg")

>>Also, could you please tell me how does the size in kb changes?

Making the image bigger increases the size (in kb), making it smaller decreases the size.

Wayne
0
 
LVL 1

Author Closing Comment

by:nectarios777
ID: 31469929
Many thanks!
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 21850973
* Just a side note...you are NOT creating a JPEG with your code!

What you have done in this line:

    bmp.Save("C:\" & imagename & ".jpg")

...is create a Bitmap with a .jpg extension.

To write as a JPEG, use the second parameter of Save():

    bmp.Save("C:\" & imagename & ".jpg", Imaging.ImageFormat.Jpeg)
0
 
LVL 1

Author Comment

by:nectarios777
ID: 21851036
Oh, I see.

Thanks.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now