Results 1 to 4 of 4

Thread: [RESOLVED] How to resize an image in windows Mobile application?

  1. #1

    Thread Starter
    Addicted Member scsfdev's Avatar
    Join Date
    Feb 2008
    Location
    Singapore
    Posts
    224

    Resolved [RESOLVED] How to resize an image in windows Mobile application?

    Hi all,

    U have any idea of how to resize an image in windows mobile application by using .net 2005?

    Here is what i did but got error.

    Code:
    Dim bitmap As New Bitmap("\img\1.jpeg")
            Dim newbit As New Bitmap(150, 150)
            Dim g As Graphics
            g = Graphics.FromImage(newbit)
            ' g.InterpolationMode = InterpolationMode.HighQualityBicubic
            g.DrawImage(bitmap, 0, 0)
            newbit.Save("\img\a.jpeg", Imaging.ImageFormat.Jpeg)
    when it hit newbit.Save method, it throws "Not supported Exception". What should I do?????

    And it also not support InterpolationMode.

    i dont know other methods.
    i can test this code in vb.net windows application with no error but not in mobile.
    Any ideas?

    thanks
    I'm using VS 2005 & 2008 & 2010 with SQL Server 2005 Express.

    My hobby beside programming: http://dslrstranger.wordpress.com

  2. #2
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: How to resize an image in windows Mobile application?

    Hey,

    Have you written the above code directly into the IDE, or have you copied and pasted from a Desktop application?

    If so, then not everything that is supported in the .Net Framework is supported in .Net Compact Framework.

    Gary

  3. #3

    Thread Starter
    Addicted Member scsfdev's Avatar
    Join Date
    Feb 2008
    Location
    Singapore
    Posts
    224

    Re: How to resize an image in windows Mobile application?

    Quote Originally Posted by gep13
    Hey,

    Have you written the above code directly into the IDE, or have you copied and pasted from a Desktop application?

    If so, then not everything that is supported in the .Net Framework is supported in .Net Compact Framework.

    Gary
    Hi gep13,
    thanks for your advice.
    I wrote the above code in IDE.
    Sorry. now its working. (cuz i test it from Win CE Emulator n it prompt error. now i test with Real device and its working. don't know why.) Except InterpolationMode . it still not supports
    sorry my mistake.

    Another issue.
    can u give me some hints about how to resize not crop the image? (the above function is working now but it seems like cropping not resizing.)
    Last edited by scsfdev; Mar 9th, 2009 at 03:18 AM. Reason: Add text
    I'm using VS 2005 & 2008 & 2010 with SQL Server 2005 Express.

    My hobby beside programming: http://dslrstranger.wordpress.com

  4. #4

    Thread Starter
    Addicted Member scsfdev's Avatar
    Join Date
    Feb 2008
    Location
    Singapore
    Posts
    224

    Smile Re: How to resize an image in windows Mobile application?

    Currently I'm solving how to resize image and move it to new location in HandHeld Windows CE 5.0 based terminals.

    Here is what I did. (May be my methods is not the perfect or correct one but for those who also face difficulty like me, it will be good for them to make references.
    Hey!! don't forget learn it on your own. And references others and learn how they did it Programming is a kind of funny things at some pont :P )

    P.S: Please tell me if this is against the forum law to post like this. So, i can remove it asap. Thanks.

    VB.Net Code:
    1. ''' <summary>
    2.     ''' Resize the target image, save it to new location and delete old one.
    3.     ''' </summary>
    4.     ''' <param name="strFileName">Original/Source File Name.</param>
    5.     ''' <remarks>
    6.     ''' Imports System.IO at the beginning.
    7.     ''' This is tested and work well on Windows CE 5.0 based HandHeld Terminals only.
    8.     ''' Not tested in another platform yet.
    9.     ''' </remarks>
    10.     ''' <Owner>By SCSFDEV @ March 10, 2009 (9:55 AM)</Owner>
    11.     ''' <contact>[email protected]</contact>
    12.     Private Sub ResizeNMoveImage(ByVal strFileName As String)
    13.         Try
    14.             ' Create a bitmap file for original image.
    15.             Dim srcmap As New Bitmap(strFileName)
    16.  
    17.             ' This is where the new image will temp stored. 150x150.
    18.             Dim destbit As New Bitmap(150, 150)
    19.  
    20.             ' The size of the source image.
    21.             Dim srcRec As New Rectangle(0, 0, srcmap.Width, srcmap.Height)
    22.  
    23.             ' The size of the destination image.
    24.             Dim destRec As New Rectangle(0, 0, 150, 150)
    25.  
    26.             ' Start a graphics whose host is new bitmap.
    27.             Dim g As Graphics
    28.             g = Graphics.FromImage(destbit)
    29.  
    30.             ' Load image in graphics.
    31.             g.DrawImage(srcmap, destRec, srcRec, GraphicsUnit.Pixel)
    32.  
    33.             ' Define the destination target location file path.
    34.             Dim strPath As String = ""
    35.             strPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly.GetName.CodeBase)
    36.  
    37.             ' Save the new image to the above location with whatever file name you want.
    38.             ' Eg > "Your application path\image\a.jpeg".
    39.             ' or > "Program Files\[application name]\image\a.jpeg".
    40.             destbit.Save(strPath & "\image\a.jpeg", Imaging.ImageFormat.Jpeg)
    41.  
    42.             ' If Old file exist?
    43.             If File.Exists(strFileName) Then
    44.                 ' Delete it.
    45.                 File.Delete(strFileName)
    46.             End If
    47.         Catch ex As Exception
    48.             ' If there is some exception, Show it on screen. (Not recommented for End user.
    49.             ' Should display some message instead of this ex.message and should write to Log file for developers to debug.)
    50.             MessageBox.Show(ex.Message, "Error@ResizeNMoveImage", MessageBoxButtons.OK, MessageBoxIcon.Hand, _
    51.             MessageBoxDefaultButton.Button1)
    52.         End Try
    53.     End Sub

    Cheers!!!!
    I'm using VS 2005 & 2008 & 2010 with SQL Server 2005 Express.

    My hobby beside programming: http://dslrstranger.wordpress.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width