|
-
Nov 12th, 2007, 08:29 AM
#1
Thread Starter
Fanatic Member
[2005] Image Mode
I want to allow the user to select a file from the file system to use on a web page, but images that are CMYK as opposed to RGB, will not display in web browsers and I wanted to know if there was any type of image analyzing I could do when the user selects the file to determine if the image is a "valid" web image?
-
Nov 12th, 2007, 12:24 PM
#2
Addicted Member
Re: [2005] Image Mode
Look at the picture PixelFormat. Lookup PixelFormat enumeration in help for a list of image types.
Code:
Public Structure ImageInformation
Dim Extension As String
Dim FileExist As Boolean
Dim FullFileName As String 'Full path and file name of image.
Dim HorizontalResolution As Single 'Horizontal resolution, in pixels per inch.
Dim ImageSize As pdfImageSize
Dim Length As Double 'Length of a file in bytes.
Dim Name As String 'Image file name without path.
Dim PDFName As String 'Internal name of image loaded into the pdf document.
Dim PixelFormat As String 'The pixel format defines the number of bits of memory associated with one pixel of data. The format also defines the order of the color components within a single pixel of data.
Dim VerticalResolution As Single 'Vertical resolution, in pixels per inch.
Dim ValidImage As Boolean
End Structure
Public Function GetImageFileInfo(ByVal ImageFileName As String) As ImageInformation
Dim tmpInfo As New ImageInformation
If Not System.IO.File.Exists(ImageFileName) Then
tmpInfo.ValidImage = False
Return tmpInfo
End If
Dim ioFile As New System.IO.FileInfo(ImageFileName)
Dim bit As New Bitmap(ImageFileName)
Try
tmpInfo.Extension = ioFile.Extension
tmpInfo.FileExist = True
tmpInfo.FullFileName = ImageFileName
tmpInfo.HorizontalResolution = bit.HorizontalResolution
tmpInfo.Length = FileLen(ImageFileName)
tmpInfo.PixelFormat = bit.PixelFormat.ToString
tmpInfo.Name = ioFile.Name
tmpInfo.ImageSize = New pdfImageSize(bit.Width, bit.Height)
tmpInfo.ValidImage = True
tmpInfo.VerticalResolution = bit.VerticalResolution
Catch ex As Exception
tmpInfo.FullFileName = ImageFileName
tmpInfo.ValidImage = False
Finally
bit.Dispose()
End Try
Return tmpInfo
End Function
-
Nov 12th, 2007, 01:06 PM
#3
Thread Starter
Fanatic Member
Re: [2005] Image Mode
The PixelFormat for my RGB image and CMYK image return the same values, yet the RGB image is supported and the CMYK image is not. Any other suggestions?
-
Nov 12th, 2007, 02:17 PM
#4
Addicted Member
Re: [2005] Image Mode
How about converting them to a format you can used?
Try:
Code:
Public Function ReCreateImage(ByVal ImageFileName As String, ByVal NewImageFileName As String, ByVal NewResolution As Single) As Boolean
If ImageFileName = String.Empty Then
MessageBox.Show("'Image File Name' is required for ReCreateImage.", "vbPDF Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return False
End If
If NewImageFileName = String.Empty Then
MessageBox.Show("'New Image File Name' is required for ReCreateImage.", "vbPDF Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return False
End If
If Not System.IO.File.Exists(ImageFileName) Then Return False
Dim orginalImage As New Bitmap(ImageFileName)
Try
If System.IO.File.Exists(NewImageFileName) Then System.IO.File.Delete(NewImageFileName)
orginalImage.SetResolution(NewResolution, NewResolution)
orginalImage.Save(NewImageFileName, System.Drawing.Imaging.ImageFormat.Jpeg)
orginalImage.Dispose()
Catch exIO As System.IO.IOException
MessageBox.Show("IOException in reCreateImage." & Environment.NewLine & Environment.NewLine & exIO.Message, "vbPDF Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return False
Catch ex As Exception
MessageBox.Show("Exception in reCreateImage." & Environment.NewLine & Environment.NewLine & ex.Message, "vbPDF Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return False
Finally
orginalImage.Dispose()
End Try
Return True
End Function
-
Nov 12th, 2007, 02:29 PM
#5
Thread Starter
Fanatic Member
Re: [2005] Image Mode
Good alternative, it would be nice to let them know that I am creating a new image as opposed to using a new one. Is there any way to determine if the image is supported in HTML?
-
Nov 12th, 2007, 04:03 PM
#6
Re: [2005] Image Mode
GDI does not have a way to determine if the image is CMYK so atm your best option is to convert the images to an acceptable format for the web. If you save the image copy as a jpg, I have found that it retains the CMYK format. I personally change them to RGB PNG images and it works fine.
here is the code I use for easily converting it to an 8bit RGB png
Code:
Dim inImage As Bitmap = Image.FromFile("C:\test.jpg")
Dim imgRegion As RectangleF = inImage.GetBounds(System.Drawing.GraphicsUnit.Pixel)
Dim outImage As Bitmap = inImage.Clone(imgRegion, Imaging.PixelFormat.Format24bppRgb)
outImage.Save("C:\text_copy.png", System.Drawing.Imaging.ImageFormat.Png)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|