473,395 Members | 1,348 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Flip image vertically in Compact Framework

Hi,

I have been trying to flip an image vertically before saving in disk in AVI format. I really dont know why i need to flip it first before saving, any idea?

To do this currently i am performing a simple algorithm...

Expand|Select|Wrap|Line Numbers
  1.         public Bitmap RotateFlip(Bitmap source, RotateFlipType change)
  2.         {
  3.             Bitmap dest = new Bitmap(source.Size.Width, source.Size.Height);
  4.             int MaxWidthIndex = source.Size.Width - 1;
  5.             int MaxHeightIndex = source.Size.Height - 1;
  6.  
  7.             for (int X = 0; X < source.Size.Width; X++)
  8.             {
  9.                 for (int Y = 0; Y < source.Size.Height; Y++)
  10.                 {
  11.                     switch (change)
  12.                     {
  13.                         case RotateFlipType.RotateNoneFlipY:
  14.                             dest.SetPixel(MaxWidthIndex - X, Y, source.GetPixel(MaxWidthIndex - X, MaxHeightIndex - Y));
  15.                             break;
  16.                         default:
  17.                             throw new Exception("Not implemented");
  18.                     }
  19.                 }
  20.             }
  21.  
  22.             return dest;
  23.         }
  24.  
  25.  
This works correctly but has severe performance bottleneck. I guess due to Set & Get pixel methods.

If you know a better approach and can share code with me, I will really appreciate.

Thanks,
Shailendra
Mar 2 '10 #1
6 4392
tlhintoq
3,525 Expert 2GB
TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.
Mar 2 '10 #2
tlhintoq
3,525 Expert 2GB
I really dont know why i need to flip it first before saving
Then why are you doing it?

before saving in disk in AVI format.
Excuse me? You're saving your bitmap as an avi? Why?

http://msdn.microsoft.com/en-us/libr...0).aspx?ppud=4
Mar 2 '10 #3
Hi,

Thanks for reply... answers to your questions...


Then why are you doing it?

Bcoz i have to. If i dont, when i play recorded video, i see vertically flipped images being displayed.

Excuse me? You're saving your bitmap as an avi? Why?

Sorry I made an ambiguous statement. What i meant is, i am getting images from a netwrok camera and i want to record it as video. so to record video i am using AVI library (found a wrapper on code project), which allow me to add images into a video stream. However it is required to perform a flip before saving an image (this is the part i am not sure about).

I hope i m clear this time :)

Thanks
Shailendra
Mar 8 '10 #4
GaryTexmo
1,501 Expert 1GB
I don't know of a faster way to do a image flip than to just parse through the data and change it around. The only way I could say to optimize it would be that you could remove the switch statement in your code. Maybe set up some variables depending on the value...

Expand|Select|Wrap|Line Numbers
  1. destImage.SetPixel((direction * x) + startX, (direction * y) + startY);
Where direction is 1 or -1 and startX/Y is 0 or the width/height accordingly.

There may be faster ways, but unfortunately I don't know them. Sorry!
Mar 8 '10 #5
Thank you very much Gary for suggesting improvement. I will try this one.
Mar 8 '10 #6
GaryTexmo
1,501 Expert 1GB
Hmm, additionally it seems there's a built-in method on the Image class.

http://social.msdn.microsoft.com/For...d-6e7907fd5e16

I don't know if it's any faster or not though, worth a try? I can't help but wonder if you know about this though 'cause you're using the same terminology and the same enum. If it's a matter of having it on a Bitmap class vs. an Image class, I'm pretty sure you can load a bitmap into an Image and vice versa. Some googling might be in order there though.
Mar 8 '10 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Earle Oxner | last post by:
We are developing an application on PocketPC2002 platform and we are trying to make webservice calls using HTTPS. HTTP works fine but HTTPS does not work. The same code which doesn't work on...
1
by: Asad Khan | last post by:
Hi, I have Visual Studio 2002 Enterprise Architecture Edition. I was wondering if anyone has any information on how I can develop applications for .Net Compact Framework using this IDE. I've heard...
2
by: RicercatoreSbadato | last post by:
I have to flip vertically a Bitmap. Is it possible with GDI+ and C#?
0
by: b. hotting | last post by:
Hi, Is there a way to zoom in on an image in the PictureBox (on Compact Framework)? or to add scrollbars which means i would be able to pan/move my image within the picturebox? thanks, bjorn
2
by: marco | last post by:
I'm a newbie and i'm doing a little application in C# for a Pocket PC that open image. I don't understand what i've to do to have a zoom of an image...i don't know where's the error. If anyone...
5
by: bob | last post by:
Hi Using 2003 - targeting the compact framework (c#), but would like to do most development using the full.net (manually leaving out stuff not in the compact framework). Q. Trying to find a...
4
by: avi | last post by:
Hello, I am trying to vertically center text in a background image, I found a solution on this site that sets the line-height to the height of the background image. This works just fine, except...
6
by: Francesco Moi | last post by:
Hi. I'd like to flip horizontally an image with JavaScript. Is it possible? Thank you very much.
3
by: Greg | last post by:
Hello all, I am looking to download an image from a website from within a compact framework pda app. I have tried everything I could find and thus I turn to you. Any help or suggestions would be...
1
by: gangui | last post by:
I need to use an image with opacity for my project, but when I import this with the method bitmap, the image miss the opacity. Since the image is a circle, I also tried to draw the image with the...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.