[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
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
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.)
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:
''' <summary>
''' Resize the target image, save it to new location and delete old one.
''' </summary>
''' <param name="strFileName">Original/Source File Name.</param>
''' <remarks>
''' Imports System.IO at the beginning.
''' This is tested and work well on Windows CE 5.0 based HandHeld Terminals only.
''' Not tested in another platform yet.
''' </remarks>
''' <Owner>By SCSFDEV @ March 10, 2009 (9:55 AM)</Owner>
Private Sub ResizeNMoveImage(ByVal strFileName As String)
Try
' Create a bitmap file for original image.
Dim srcmap As New Bitmap(strFileName)
' This is where the new image will temp stored. 150x150.
Dim destbit As New Bitmap(150, 150)
' The size of the source image.
Dim srcRec As New Rectangle(0, 0, srcmap.Width, srcmap.Height)
' The size of the destination image.
Dim destRec As New Rectangle(0, 0, 150, 150)
' Start a graphics whose host is new bitmap.
Dim g As Graphics
g = Graphics.FromImage(destbit)
' Load image in graphics.
g.DrawImage(srcmap, destRec, srcRec, GraphicsUnit.Pixel)
' Define the destination target location file path.
Dim strPath As String = ""
strPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly.GetName.CodeBase)
' Save the new image to the above location with whatever file name you want.
' Eg > "Your application path\image\a.jpeg".
' or > "Program Files\[application name]\image\a.jpeg".
destbit.Save(strPath & "\image\a.jpeg", Imaging.ImageFormat.Jpeg)
' If Old file exist?
If File.Exists(strFileName) Then
' Delete it.
File.Delete(strFileName)
End If
Catch ex As Exception
' If there is some exception, Show it on screen. (Not recommented for End user.
' Should display some message instead of this ex.message and should write to Log file for developers to debug.)
MessageBox.Show(ex.Message, "Error@ResizeNMoveImage", MessageBoxButtons.OK, MessageBoxIcon.Hand, _
MessageBoxDefaultButton.Button1)
End Try
End Sub
Cheers!!!!