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 ?
Private Sub BitmapConstructorEx(ByVal e As PaintEventArgs)
' Create a bitmap.
Dim bmp As New Bitmap("c:\fakePhoto.jpg")
' Retrieve the bitmap data from the the bitmap.
Dim bmpData As System.Drawing.Imaging.BitmapData = bmp.LockBits(New Rectangle(0, 0, bmp.Width, bmp.Height), _
ImageLockMode.ReadOnly, bmp.PixelFormat)
'Create a new bitmap.
Dim newBitmap As New Bitmap(200, 200, bmpData.Stride, bmp.PixelFormat, bmpData.Scan0)
bmp.UnlockBits(bmpData)
' Draw the new bitmap.
e.Graphics.DrawImage(newBitmap, 10, 10)
End Sub
None
0 Points
1 Post
Resize CMYK Images
Nov 02, 2013 10:23 AM|khodayari|LINK
Hello
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):
When I replace Line:
With :
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 ?
All-Star
15648 Points
2151 Posts
Re: Resize CMYK Images
Nov 19, 2013 01:57 AM|Happy Chen - MSFT|LINK
hi khodayari ,
i would suggest you try the workaround:
Please refer to the link below:
Bitmap Constructor (Int32, Int32, Int32, PixelFormat, IntPtr)
http://msdn.microsoft.com/en-us/library/zy1a2d14.aspx
http://msdn.microsoft.com/en-us/library/vstudio/ms616045(v=vs.100).aspx
Member
10 Points
17 Posts
Re: Resize CMYK Images
Jan 15, 2014 09:55 PM|mickwen|LINK
Hello,
Check this solution,
http://www.codeproject.com/Tips/552141/Csharp-Image-resize-convert-and-save