Solved

resize image

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

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

Suggested Solutions

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
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 …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

726 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