Saving Large Photographs on WM6 CF2.0

Posted on 2007-11-27
Last Modified: 2013-12-05
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:
64 MB
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
        fileName = ccd.FileName
        PictureBox1.Image = New Bitmap(fileName)'the exception occurs here


Question by:bean_ian
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
LVL 24

Expert Comment

ID: 20357164
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?


Author Comment

ID: 20357186
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.
LVL 24

Expert Comment

ID: 20357343
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:

so the bottom line is to minimize memory usage on copying objects back and forth
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 20357395
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
LVL 24

Accepted Solution

alexey_gusev earned 450 total points
ID: 20357453
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.

Author Closing Comment

ID: 31411170
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

Author Comment

ID: 20358983
Here is the code for anyone who is interested:
Dim ccd As New CameraCaptureDialog
        ccd.Mode = CameraCaptureMode.Still
        ccd.StillQuality = CameraCaptureStillQuality.Default
        fileName = ccd.FileName

        '    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)

Featured Post

Containers & Docker to Create a Powerful Team

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Determining the an SCCM package name from the Package ID
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

623 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