Hi, part of my application uploads a file to a remote webserver. One of the
conditions is that the uploaded image *must be* a RGB JPEG
Does anyone have any idea how I can test to see if the uploaded image is a
RGB JPEG?
I looked at the PostedFile.getContentType() and this does tell me the type
of the file (JPEG) but not if the image was a RGB JPEG. The returned
information from the PostedFile.getContentType() also varies from browser to
browser
TIA
Mark
1st I beliebe that all JPG are RGB, aren't they?
anyway what about loading the image and check it's color type?
mmh.... maybe you don't know how?
here is an idea of pseudo-code-solution
bool IsMyImageType(Stream data)
{
try
{
using(Bitmap bmp = new Bitmap(data))
{
if(!bmp.ImageFormat.Equals(ImageFormat.Jpeg))
return false;
switch(bmp.PixelFormat)
{
default:
return false;
// as far as I believe only the 1st case is really needed
for a JPEG file
case PixelFormat.Format32bppRgb:
case PixelFormat.Format16bppArgb555:
case PixelFormat.Format16bppRgb555:
case PixelFormat.Format16bppRgb565:
case PixelFormat.Format24bppRgb:
case PixelFormat.Format24bppArgb:
case PixelFormat.Format32bppAgb:
case PixelFormat.Format32bppPArgb:
case PixelFormat.Format48bppRgb:
case PixelFormat.Format64bppArgb:
case PixelFormat.Format64bppRgb:
return true;
}
}
return bm
}
catch { return false; }
}
> Hi, part of my application uploads a file to a remote webserver. One of
> the
[quoted text clipped - 11 lines]
> TIA
> Mark
Mark - 13 Sep 2005 05:50 GMT
Hi, thanks for your help. I'll take a look at what you have recommended
below :)
Cheers
Mark
> 1st I beliebe that all JPG are RGB, aren't they?
> anyway what about loading the image and check it's color type?
[quoted text clipped - 48 lines]
> > TIA
> > Mark