Results 1 to 6 of 6

Thread: [2005] Image Mode

  1. #1

    Thread Starter
    Fanatic Member clarkgriswald's Avatar
    Join Date
    Feb 2000
    Location
    USA
    Posts
    799

    Exclamation [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?

  2. #2
    Addicted Member
    Join Date
    Mar 2006
    Posts
    235

    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

  3. #3

    Thread Starter
    Fanatic Member clarkgriswald's Avatar
    Join Date
    Feb 2000
    Location
    USA
    Posts
    799

    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?

  4. #4
    Addicted Member
    Join Date
    Mar 2006
    Posts
    235

    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

  5. #5

    Thread Starter
    Fanatic Member clarkgriswald's Avatar
    Join Date
    Feb 2000
    Location
    USA
    Posts
    799

    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?

  6. #6
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    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)
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

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