Solved

resize image

Posted on 2007-04-03
4
199 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 85

Accepted Solution

by:
Mike Tomlinson earned 500 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 85

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
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 …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

839 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