Startsidan  ▸  Texter  ▸  Teknikblogg

Anders Hesselbom

Programmerare, skeptiker, sekulärhumanist, antirasist.
Författare till bok om C64 och senbliven lantis.
Röstar pirat.

WsImage.Image

2009-05-31

For quite some time, I have had the need for some extra high level functionality on top of the .NET Bitmap class. I want to be able to do some basic image manipulation and I want the typical functionality that you would expect from a content management system, like cropping and resizing. This is why I have started to build the WsImage.Image class. And I mean that I really just have started. Today. It is written in Visual Basic, but I have avoided the “VB only” features, like parameterized properties, so it works perfectly in a C#-project or Managed C++-project.

It is a disposable object, use the Using keyword to create it (as you would with any disposable object). One constructor takes a desired with and height, and another takes the filename of an existing image.

The WsImage.Image class wraps the .NET Bitmap class, and here is the current API (believe me, this is going to change in the future):

CreateGraphics
Returns a Graphics object.

CropToRectangle
Makes the image rectangular. For a image that is wider than it is high, the hight will not change, and the width will be cropped to match the height. The cropping is centered.

GetBitmap
This simply returns the Bitmap object that is contained in the WsImage.Image object. Do not dispose this object, just forget it when you’re done with it.

GetProportions
Returns a Size object that describes the proportions of the image. For example, an image sized 1000×1000 pixel will return a size object with the value 1×1, an image sized 17×11 pixels will return a size object with the value 17×11, an image sized 800×600 pixels will return a size object with the value 4×3 and so on.

GetSize
Returns the size of the image.

GetThumbnail
Returns a thumbnail as a .NET Bitmap. Currently, there is no overload for actually requesting the size of the thumbnail, it simply gives you a 100 pixels wide version of image. If the image is less than 100 pixels wide, black border is added – zooming will not occur. Dispose the returned Bitmap when you are finished with it.

Yes, you can download the compiled class here, but if you’re not deadly interested in it, you could wait until it has a few more features in it. Like I said, I started today. If you do use it, remember to credit me in the about box.

Categories: Microsoft .NET

Tags: WsImage

Leave a Reply

Your email address will not be published. Required fields are marked *



En kopp kaffe!

Bjud mig på en kopp kaffe (20:-) som tack för bra innehåll!

Bjud på en kopp kaffe!

Om...

Kontaktuppgifter, med mera, finns här.

Följ mig

Twitter Instagram
GitHub RSS

Public Service

Folkbildning om public service.

Hem   |   linktr.ee/hesselbom   |   winsoft.se   |   80tal.se   |   Filmtips