Solved

Saving Large Photographs on WM6 CF2.0

Posted on 2007-11-27
7
568 Views
Last Modified: 2013-12-05
Hi,
I have a small application that runs on a HTC Touch device. Basically it takes a picture and saves it to a sql server database via a webservice.
The device is running Windows Mobile 6 and the app i developed is running on compact framework 2.0.
The application works fine when using the Small,Medium or Large quality setting on the camera, however if I use the 1megapixel or 2megapixel setting I get a OutOfMemoryException after the picture is taken when i try load the freshly taken picture into a bitmap object.
Here is the memory spec for this device:
RAM
64 MB
 
ROM
128 MB

Any ideas how i can overcome this problem and save a 2mp picture? It is a requirement of the project that
the picture resolution is 2mp.
here is the code im using:

 Dim fileName As String = String.Empty
        Dim ccd As New CameraCaptureDialog
        ccd.Mode = CameraCaptureMode.Still
        ccd.StillQuality = CameraCaptureStillQuality.High
        ccd.ShowDialog()
        fileName = ccd.FileName
        Show()
        PictureBox1.Image = New Bitmap(fileName)'the exception occurs here

        ccd.Dispose()

Cheers
IAn
0
Comment
Question by:bean_ian
  • 4
  • 3
7 Comments
 
LVL 24

Expert Comment

by:alexey_gusev
Comment Utility
Hi Ian,

is it a must to display newly taken picture? and how do you send it to remote database? maybe it is possible in your design just to read binary data from the file and send it over?

BR,
Alex
0
 

Author Comment

by:bean_ian
Comment Utility
Yeah the user has to see the taken picture(in order to decide if it needs to be taken again). It is sent to the DB via a webservice(converted to a byte array then in the Webservice converted back to a bitmap). Doesnt even get that far though so that code is not an issue.
0
 
LVL 24

Expert Comment

by:alexey_gusev
Comment Utility
well, in order to investigate the possible solutions, I would check the memory usage, e.g. if PictureBox.Image is already allocated, how much memory is needed etc.

then I'd try something like this:

http://msdn2.microsoft.com/en-us/library/5ey6h79d.aspx

so the bottom line is to minimize memory usage on copying objects back and forth
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:bean_ian
Comment Utility
I tried using lockbits to no avail. It makes no difference weather or not i load the image into PictureBox.Image or a brand new bitmap object, the same exception gets thrown
0
 
LVL 24

Accepted Solution

by:
alexey_gusev earned 450 total points
Comment Utility
so does it mean that there is absolutely no (or not enough) free memory left at that moment? maybe try to ccd.Dispose() prior to dealing with Bitmap.

in case of "no memory available" I don't see many options left. I believe that sending binary data to web service won't be a problem at all, and the main issue is to display taken picture. Unless you find a way to reduce the memory usage by your application, you probably might convert the image to the lower resolution and display it if it is acceptable. or may be convert it to different format which requires less memory.
0
 

Author Closing Comment

by:bean_ian
Comment Utility
Thanks alexey. I used your idea and used OpenNetCf 2.1 imaging classes to create a thumbnail and display that and then write the large file directly to the DB.
Thanks for your help
0
 

Author Comment

by:bean_ian
Comment Utility
Here is the code for anyone who is interested:
Dim ccd As New CameraCaptureDialog
        ccd.Mode = CameraCaptureMode.Still
        ccd.StillQuality = CameraCaptureStillQuality.Default
        ccd.ShowDialog()
        fileName = ccd.FileName
        Show()

        '    bmp = New Bitmap(fileName)
        'bmpEx = New BitmapEx(ccd.FileName)
        Dim oFile As System.IO.FileInfo
        oFile = New System.IO.FileInfo(fileName)
        Dim oFileStream As System.IO.FileStream = oFile.OpenRead()
        ibitmap = OpenNETCF.Drawing.Imaging.ImageUtils.CreateThumbnail(oFileStream, New Drawing.Size(234, 181))
        PictureBox1.Image = OpenNETCF.Drawing.Imaging.ImageUtils.IBitmapImageToBitmap(ibitmap)
        ccd.Dispose()
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now