Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I flip an image horizontally in .net web app

I need to flip a bitmap image horizontally in my VB.net web application.

i.e.

enter image description here

I've really searched around, but not come across any simple vb.net method. Does one exist?

like image 659
Urbycoz Avatar asked Oct 22 '22 12:10

Urbycoz


1 Answers

You get a file reference to the image, load that as a Bitmap, then use the RotateFlip method.

http://msdn.microsoft.com/en-us/library/system.drawing.rotatefliptype.aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2

In case that link dies as Microsoft is oft known to do:

    bitmap1 = CType(Bitmap.FromFile("C:\Documents and Settings\All Users\" _
        & "Documents\My Music\music.bmp"), Bitmap)
    bitmap1.RotateFlip(RotateFlipType.RotateNoneFlipX)

You may be interested in the Image class (a Bitmap is an Image). You can perform just about any naive operation (like this one), and there are ways to leverage the 3D card to really go crazy. You can take it really far. You need to learn graphics matrices to do custom effects performantly, though.

http://msdn.microsoft.com/en-us/library/k7e7b2kd.aspx

Edit

Comments on the question note performance can be an issue here. Depending on how often an image like this is loaded you likely should cache the results of this, for example by writing it to disk and having the browser actually request the file by the path it was written out to (which will get you whatever IIS caching you've configured for free), or by applying an OutputCache directive to the Controller Action being called here, or whatever - kinda outside the scope of this question.

Also just for the record flipping an image is pretty cheap.

like image 190
Chris Moschini Avatar answered Nov 15 '22 09:11

Chris Moschini