Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / June 2007

Tip: Looking for answers? Try searching our database.

Save images to memorystream?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Stupid48 - 23 Jun 2007 01:57 GMT
I'm writing a simple screen capture program that is using the Bitmap
class to save the capture.  I would like to do multiple captures and
save them as we go along.  I know that I could save them to a
temporary folder on the filesystem but is there a way to save them to
memory (i.e. memorystream) and, if so, how do I reference them later
(C# or VB.Net is fine)?

Thanks, Chris
Peter Duniho - 23 Jun 2007 10:40 GMT
> I'm writing a simple screen capture program that is using the Bitmap
> class to save the capture.  I would like to do multiple captures and
> save them as we go along.  I know that I could save them to a
> temporary folder on the filesystem but is there a way to save them to
> memory (i.e. memorystream) and, if so, how do I reference them later
> (C# or VB.Net is fine)?

Have you looked at the Image.Save() method that takes a Stream as a  
parameter?
http://msdn2.microsoft.com/en-us/library/ms142147.aspx

You would create the MemoryStream, save to it, and then use  
Image.FromStream() later to reconstitute the image.

That said, if you just want to keep the images in memory, why not just do  
that?  What's the point of stuffing it into a MemoryStream if all you're  
going to do is read it back out again?  Just keep your Image (Bitmap)  
reference around, and use it as needed.

Pete
Stupid48 - 28 Jun 2007 01:41 GMT
On Jun 23, 2:40 am, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
> > I'm writing a simple screen capture program that is using the Bitmap
> > class to save the capture.  I would like to do multiple captures and
[quoted text clipped - 15 lines]
>
> Pete

I see your point.  I would like to not have to save it at all.  There
is a possibility that there will be multiple bitmaps captured one
after another.  I guess I just don't know how to save all of the
references to them and be able to access them later by some sort of
index.  My function is:

       ' Grab the selected piece of the image.
       Dim rect As New Rectangle( _
           Min(m_X1, m_X2), Min(m_Y1, m_Y2), _
           Abs(m_X1 - m_X2), Abs(m_Y1 - m_Y2))
       Dim bm As Bitmap = DirectCast( _
           m_bmDesktop.Clone(rect, m_bmDesktop.PixelFormat), Bitmap)

       ' Save the image into the file.
       bm.Save(file_name, ImageFormat.Jpeg)

So, instead of bm.save, I would like to create some sort of collection
that I can reference later.  Can someone give me a pointer on how to
do that?

Thanks, Chris
Peter Duniho - 28 Jun 2007 03:53 GMT
> [...]
> So, instead of bm.save, I would like to create some sort of collection
> that I can reference later.  Can someone give me a pointer on how to
> do that?

How about an array?  There are a number of potential solutions that are  
either arrays or are array-like, all very basic data structures that  
should be known to anyone attempting to write any useful program.  Or put  
another way, if you want to write useful programs, it sounds as though you  
may want to educate yourself a little more on basic data structures common  
to all programming environments.

As far as your specific question goes, some examples of data structures  
that would be useful to you:

    Dim arrayOfBitmaps As List(Of Bitmap)
    Dim arrayOfBitmaps As ArrayList
    Dim arrayOfBitmaps() As Bitmap

Any of those variable declarations will result in a variable named  
"arrayOfBitmaps" in which you can store an arbitrary number of Bitmap  
instances.  With the first two, you can add new elements using an Add()  
method each of the classes has.  I believe with the third, you would need  
to use ReDim() to resize the array as new items are added, if you did not  
intially create an array large enough for all of your items.

Hope that helps.

Pete
Stupid48 - 28 Jun 2007 15:37 GMT
On Jun 27, 7:53 pm, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
> > [...]
> > So, instead of bm.save, I would like to create some sort of collection
[quoted text clipped - 25 lines]
>
> Pete

Thanks for the info.  I didn't know that one could put these datatypes
in an array.  I guess being a novice, I have a lot to learn but I
guess we all have to start somewhere....
Peter Duniho - 28 Jun 2007 17:36 GMT
> Thanks for the info.  I didn't know that one could put these datatypes
> in an array.  I guess being a novice, I have a lot to learn but I
> guess we all have to start somewhere....

Yup, that's true.  We did all start somewhere, and we did all have a  
moment when we had to learn what you can put into an array.  This just  
happened to be yours.  :)

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.