Display images - C#

  • Thread starter Thread starter Dafna m
  • Start date Start date
D

Dafna m

Please HELP

1. How can I display an array of images from diffrent types(jpeg,
bmp..)(In C#)
Can I also display video files?(In C#)
 
Dafna m said:
Please HELP

1. How can I display an array of images from diffrent types(jpeg,
bmp..)(In C#)
Can I also display video files?(In C#)

There are many ways to do this. See PictureBox, and the classes Image and
Bitmap. Note that Bitmap can load from files from many, many types.

This link should give you more than enough info for what you want for
pictures.
http://www.codeproject.com/cs/media/

I'd first look at the article "How to load/display images"
http://www.codeproject.com/cs/media/quickview.asp

As for videos, you have three choices (probably more than this)
1) Managed DirectX 9 and the AudioVideoPlayback class
- Uses all C# code
- Documentation is not very good
- Lots of annoying bugs in the library.
- Requires DirectX 9 is installed on clients.

Here's DirectX9 SDK link:
http://www.microsoft.com/downloads/...20-9dfd-4e7a-b947-3a037ccf84af&displaylang=en

I found I had to use a LOT of workarounds to get the AudioVideoPlayback to
"play" nicely - but that was only when I started messing with the volume
level of the sound. If you don't mess with volume, it's not too hard to get
this working.

2) DirectX DirectShow and interop
- Uses Interop to get to non-native code (more complicated code)
- Much better documentation
- More stable libraries (less bugs)
- Requires only DirectX 8 or so

There are two articles on the above codeproject link on using this.

3) Use Windows Media Player ActiveX control
I've only used this slightly, didn't have much success myself.

http://msdn.microsoft.com/library/d...play/mmp_sdk/windowsmediaplayer9seriessdk.asp


I'll be happy to answer any more detailed (or more specific) questions that
you have.
 
For video:

Solution #1 is optimal. It is no different from using the Interop library
for DirectShow, the only big difference is that the DX team custom coded a
type library wrapper rather than have one that is auto-generated. This
means they do a lot of the marshalling of various types for you to make your
life easier, and supposedly make the libraries run faster. In most cases,
Managed DirectX is 97% the speed of DirectX accessed through C#. There are
some issues if you are constantly loading resources or changing vertex
buffers since all of this stuff has to be marshalled, but that can be
optimized out in most cases (basically, this can be optimized out for most
cases where you would use C# instead of C++).

Solution #2 is a bit more kludgy than solution #1. You have to learn what
kinds of types are expected in many cases, especially where IntPtr's are
being used and you have to pass things using memory. It is pretty solid
(though so is solution #1, I'm not sure which problems Mike is having) and
you shouldn't have too many problems once you get the initial playback
working.

Solution #3 is probably the easiest. You can use a type library wrapper
around the various components that ships with Media Player and have it play
all of your video back for you. If done correctly you can host a media
player control right inside of your Windows Forms application and fully
customize the playback UI if you desire. I'd say #3 is going to give you
the broadest support for Video, while #1 and #2 are going to offer you more
customization (placing filters in the DirectShow stream for example that
modify the output).

If video is really turning into a big problem for people in the Managed
world speak up. I'd be happy to sit down and write up a couple of tutorials
surrounding the kinds of things I've done with video. I'm guessing most
people haven't put a large amount of time into examining video since the
time to place it in an application versus the pay-off isn't spectacular.
 
If video is really turning into a big problem for people in the Managed
world speak up. I'd be happy to sit down and write up a couple of tutorials
surrounding the kinds of things I've done with video. I'm guessing most
people haven't put a large amount of time into examining video since the
time to place it in an application versus the pay-off isn't spectacular.

I'd be curious to see what you've done. I wrote a screensaver to show both
my jpg's and avi's from my camera (can be found here:
http://www.mag37.com/projects/screensaver/ - plug, it also does all kinds
of other things including rotating and skipping files)

I spent a lot of time trying to get the Video class to play nicely with
GDI+. That is, after playing a video, I needed to Dispose the video object
so that I could use the screen for Graphics.DrawImage calls.

My first problem was how to call Dispose for a video class. Ideally, I
would do it as a result of the Ending event. However, if I actually put a
call to Dispose in the Ending event handler function, then I'd get terrible
exceptions when my method returned (and the "calling" video class that
called my event was suddenly disposed). So instead I set a timer in the
Ending event, and had that timer dispose the Video class.

Later, when I wanted to mute the audio of the video class, I ran into more
problems. It turns out you can't even look at the Audio property of a Video
class without screwing it up. I got workarounds to get the Ending event to
fire again. But video.Dispose() still doesn't work if you do
video.Audio.anything.

I finally went to two separate forms - one for Graphics.DrawImage and one
for Video playing, with the two forms being made visible or not as needed.
I still have sporadic errors popping up when I close my application, if I
have avi video files play.

I'd like a more elegant solution - thought maybe DirectShow might work
better, but haven't gotten around to it yet.

I'd be happy to work with you on tutorials and post and/or give you some of
my code and workarounds - especially for dealing with Audio in a Video
class. Although a lot of my code is specific to trying to handle both video
and images.
 
Back
Top