BMP to JPEG - Dont be scared!!

C

Craig Hardcastle

Hi,

im writing a program that sends a video stream to a remote pc. I've
managed to get the bitmap data from the piture box control, via Bob
Nicholls earlier post.

My problem now is that the data is too big.

The code that Bob Nicholl did seems to convert the image to a 24bit
bmp, which is fine if all you want is to save it, but when it comes to
sending it over the net its just too big. As the images sizes i want
to send are 160x120 to 320x240.

So my question to you brainy lot is that seen as i have the bmp data
stored as bytes, is there anyway to convert this data into a jpeg? If
so then how? and if you have any codes samples that would be very
helpful.

I've searched google and can't seem to find the answer, so hopefully
someone out there has the answer.

Oh one final point, i'm programming in VB.NET!

Thanks,

Craig.
 
M

mhuska

Craig -
I think this will fix ya up:
Private Function SaveImageFile(ByVal imgImage As System.Drawing.Bitmap, ByVal strFilename As String) As Boolean
Dim fs As FileStream
Try
fs = New FileStream(strFilename, FileMode.CreateNew)
imgImage.Save(fs, ImageFormat.Jpeg)
fs.Close()
Catch ex As Exception
MessageBox.Show("Error occurred while saving the file: " & vbCrLf & ex.Message)
SaveImageFile = False
Finally
fs = Nothing
End Try

End Function

-Mike

**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
 
C

Chris Tacke, eMVP

Nice try! You can't call Save on an image in the CF!

--
Chris Tacke, eMVP
Co-Founder and Advisory Board Member
www.OpenNETCF.org
---
Windows CE Product Manager
Applied Data Systems
www.applieddata.net


Mike Huska said:
Craig -
I think this will fix ya up:
Private Function SaveImageFile(ByVal imgImage As
System.Drawing.Bitmap, ByVal strFilename As String) As Boolean
Dim fs As FileStream
Try
fs = New FileStream(strFilename, FileMode.CreateNew)
imgImage.Save(fs, ImageFormat.Jpeg)
fs.Close()
Catch ex As Exception
MessageBox.Show("Error occurred while saving the file: " & vbCrLf & ex.Message)
SaveImageFile = False
Finally
fs = Nothing
End Try

End Function

-Mike

**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP &
ASP.NET resources...
 
C

Craig Hardcastle

Thanks Mike But,

when i said i'm programming in VB.NET i meant VB.NET CF so the .Save
isn't supported.

Regards

Craig.
 
C

Craig Hardcastle

Yeah thanks mike but thats not supported. Though even if it was i dont
really want to save the file then have to reopen it to send it coz for
streaming thats not a effective way of doing it.

So you any ideas chris?

if it can't be converted to jpeg then could i compress it and then
send it? though jpeg wud be all my problems solved!

Craig.
 
C

Chris Tacke, eMVP

The problem is that there are no available CF compression algorithms that
I'm aware of just off the shelf. I know that there are some open-source
zip-type compression routines, and I assume there are JPG compression
routines as well, but you'll probably have to port either.
 
C

Craig Hardcastle

Come On! there must be someone out there who has done this?! if no one
can do jpeg then can someone point me to some compression code?

wot i don't get is that a picture box can load in a jpeg, so surely
that means that there sum jpeg api/dll somewhere that can be called?

Craig.
 
L

Lloyd Dupont

in this article you have the C cod to write a JPG.
there is only about 700K of C code to port to C# .....
 
C

Craig Hardcastle

hi,

thanks Lloyd and Arsa for your links. I dont suppose anyone would know
of any VB examples? it seems that the only things out there are in C,
which is ok but when it comes to porting it to VB thats a different
story.

Lloyds link was good but its not listed as supporting Pocket PC, and
Arsa's link was to and embedded example, so will that work in 2003?

Thanks,

Craig.
 
A

Arsa

Normaly it's supposed to work. You can arrange the dll and p/invoke from VB.
Porting a jpeg compression algorithm
to C# or VB woulb be very slow.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top