?
Solved

resize image

Posted on 2007-04-03
4
Medium Priority
?
202 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

800 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