Click here to Skip to main content
15,886,799 members
Articles / Mobile Apps

How to save Bitmaps from a VB PocketPC application

Rate me:
Please Sign up or sign in to vote.
3.20/5 (4 votes)
15 Aug 2004CPOL1 min read 44.7K   224   13   2
How to save Bitmaps from Pocket PC applications using VB.

Introduction

There are a number of useful functions that are missing in the .NET Framework CE. To make the most of the limited resources on mobile devices only subset of the .NET Framework have been included. The Save and FromFile functions are missing. There are 2 good examples how to do this in C# but I have not found any examples how to do this in VB. Therefore this article describes how to save and Load Bitmaps in VB.NET on a Pocket PC.

Method 1: Using the MS C# Code in VB as a Subproject

There are a number of features in C# that are not so easily converted to VB. So rather than translate everything into VB and have 2 versions to control I have just included the C# example from Microsoft as a sub project. This is done by following this recipe:

  1. Open the VB Pocket PC that requires the Bitmap functions
  2. Right mouse click on the Solution and select Add then Existing project

    Image 1

  3. Select the ImageEditor.csdproj
  4. Right mouse click on the Image Editor subproject and select properties
  5. Change Output Type to Class Library

    Image 2

  6. Right mouse click on the Image Editor and Build
  7. Click on the References folder of the VB project and Add Reference

    Image 3

  8. In the form where you would like to save the bitmap add
    VB.NET
    Imports ImageEditor

    To save the bitmap

    VB.NET
    SaveFileDialog1.Filter = "Bitmap files (*.bmp)|*.bmp"
       If SaveFileDialog1.ShowDialog() = DialogResult.OK Then
          Me.pDrawWindow.Refresh()
          ImageEditor.BitmapFile.SaveToFile(Me.pDrawWindow, 
    SaveFileDialog1.FileName, 16, Me.bitmap.Width, Me.bitmap.Height)
       End If

    To load the bitmap

    VB.NET
    OpenFileDialog1.Filter = "Bitmap files (*.bmp)|*.bmp"
       If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
          Application.DoEvents()
    
          Cursor.Current = Cursors.WaitCursor
          Dim s As Stream = File.OpenRead(OpenFileDialog1.FileName)
          Me.bitmap = New Bitmap(s)
          s.Close()
    
          Me.pDrawWindow.Invalidate()
          Cursor.Current = Cursors.Default
    
       End If

Method 2: Write the Bitmap file structure directly from VB

This method is really slow and I would not recommend that this be used. I have included it because it shows the performance benefits of using P/Invoke in the previous examples. This based on a C# example from an example from here

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Switzerland Switzerland
I am a Software Engineer currently working in a Re Insurance company.

Comments and Discussions

 
Question2 or 4 bit functionality? Pin
madman210-Dec-05 7:32
madman210-Dec-05 7:32 
Question2 or 4 bit functionality? Pin
Member 9960105-Jan-05 6:22
Member 9960105-Jan-05 6:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.