Resize CMYK Images RRS feed

  • Question

  • User11170077 posted


    I use bellow code to resize user uploaded pictures, it works fine for RGB Mode Images but when i use CMYK image i receive "Out of memory" Error in line Graphics.FromImage(resized):

    Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Dim original As Image = Image.FromFile(Application.StartupPath & "\some.jpeg")
            Dim resized As Image = ResizeImage(original, 1024, 768)
            resized.Save(Application.StartupPath & "\some2.JPG", Imaging.ImageFormat.Jpeg)
        End Sub
    Public Function ResizeImage(ByVal img As Bitmap, ByVal width As Integer, ByVal height As Integer) As Bitmap
       Dim resized As New Bitmap(width, height)
       Using g As Graphics = Graphics.FromImage(resized)
           g.DrawImage(img, resized.GetBounds(GraphicsUnit.Pixel))
       End Using
       Return resized
    End Function

    When I replace Line:

    Dim resized As New Bitmap(width, height)

    With :

    Dim resized As New Bitmap(width, height, img.PixelFormat)

    img.PixelFormat return number and it's not in pixel format standard types.

    I think the reason is Bitmap type does not support CMYK Pixel format Mode, So how can i solve this problem ?

    Saturday, November 2, 2013 10:23 AM

All replies