Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

resize image

Posted on 2007-04-03
4
Medium Priority
?
204 Views
Last Modified: 2010-04-23
Hello

I have an image with size of 60x100
Now I want to resize it, so it is 100x100, but not resize the image itself. The image itself should still be 60x100, but with 20 pix on the left and 20 pix on the right, this space should be transparent...

How can I do that?

Thanks
0
Comment
Question by:Ruttensoft
  • 2
  • 2
4 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 1500 total points
ID: 18844040
You can resize an image using code like this...

        Dim fileName As String = "c:\small.jpg"

        Dim fs As New System.IO.FileStream(fileName, IO.FileMode.Open)
        Dim img As Image = Image.FromStream(fs)
        fs.Close()

        Dim bmp As New Bitmap(100, 100)
        Dim g As Graphics = Graphics.FromImage(bmp)
        g.Clear(Color.Transparent)
        g.DrawImage(img, 20, 0)
        g.Dispose()

        img.Dispose()

        bmp.Save(fileName, System.Drawing.Imaging.ImageFormat.Jpeg)

But I'm not sure about the Transparent color part.  =\
0
 

Author Comment

by:Ruttensoft
ID: 18847173
Hi

Thanks for the hint

It's interesting, it did not work initially, the bitmap was bigger on the new drawn image.
I've now changed from filestream to direkt Image.Fromfile, and this is working
        Dim fileName As String = "c:\Portrait.png"
        Dim img As Bitmap = New Bitmap(Image.FromFile(fileName))
        Dim bmp As New Bitmap(100, 100)
        Dim g As Graphics = Graphics.FromImage(bmp)
        g.Clear(Color.Transparent)
        g.DrawImage(img, 20, 0)
        g.Dispose()
        img.Dispose()
        bmp.Save("c:\Portraita.png", System.Drawing.Imaging.ImageFormat.Png)

Then saving to png, and the transparent is also working... by jpg not...

But thanks for the hint

Sven

0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 18847442
Ok...wonder why it was resizing the image in the original code?

Glad you figured out the rest though...  =)
0
 

Author Comment

by:Ruttensoft
ID: 18847451
Hm yeah I wonder too why that was not working... very strange... but yeah... it now works, thanks for your code, without I would not have figured it out...
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Loops Section Overview

926 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