Well, I think the title mostly says it. I want to upload an image that might be in a variety of formats. In general I then want to save it as is. But if it's JPG with a CMYK color space, I want to convert the color space to RGB when I save it. Is there an easy way to do this in VB.NET? (Or a hard way?)
Asked
Active
Viewed 1,893 times
0
-
You do realize you will lose quality re-saving a JPG. I am presuming you have a specific need for RGB? – Dreamwalker Apr 16 '14 at 15:06
-
1Have you seen [onverting CMYK Jpegs to RBG format](http://www.maxostudio.com/Tut_CS_CMYK.cfm)?? seem it does what you need !!! – huMpty duMpty Apr 16 '14 at 15:07
-
@huMptyduMpty I was just digging that link out :) – Dreamwalker Apr 16 '14 at 15:08
-
I have to assume that these answers would be very helpful (although it's asking for the reverse) - http://stackoverflow.com/questions/5237104/c-sharp-convert-rgb-value-to-cmyk-using-an-icc-profile – EkoostikMartin Apr 16 '14 at 15:09
-
@Dreamwalker Sure. But my client is addicted to IE8, and IE8 cannot display CMYK JPGs -- you just get the Red X of Death. So a degraded image is better than no image at all. – Jay Apr 16 '14 at 20:29
-
@huMptyduMpty I haven't tried it yet, but it looks like what I need. Thanks. – Jay Apr 16 '14 at 20:39
1 Answers
0
This is a simple recursive CMYK to RGB JPEG converter:
<%@ OutputCache Duration="600" VaryByParam="*" %>
<%@ Page Debug="false" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Imaging" %>
<%@ Import Namespace="System.IO" %>
<script language="VB" runat="server">
' CMYK to RGB image converter v1.0
Dim MyFolder as String = "PHOTO"
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
response.write ("<!DOCTYPE html><HTML><HEAD><TITLE>CMYK to RGB converter</TITLE><STYLE>HTML {margin:0px}BODY {font-family:Arial,Helvetica,SansSerif;margin:10px}</STYLE></HEAD><BODY><H1>CMYK to RGB converter</H1><H3>v1.0 by TFI</H3><BR>Image folder: <b>"+MyFolder+"</b><BR><BR>")
Dim dir As String = Server.MapPath(".")
Dim folders() As String = Directory.GetDirectories(dir)
for each folder as String in folders
if mid(folder,InStrRev(folder,"\")+1)=MyFolder then
Dim files() As String = Directory.GetFiles(folder,"*.jpg",SearchOption.AllDirectories)
if ubound(files)>=0 then
for each file as String in files
Response.write ("Converting "+file)
Convert(file)
Response.Flush()
next
else
response.write ("No images found.")
end if
end if
Next
response.write ("</BODY></HTML>")
End Sub
Sub Convert(imageName as String)
Dim imgFullSizeTemp As System.Drawing.Image
imgFullSizeTemp = System.Drawing.Image.FromFile(imageName)
If imgFullSizeTemp Is Nothing Then Response.End()
Dim imgFullSize as new Bitmap(imgFullSizeTemp.Width, imgFullSizeTemp.Height, PixelFormat.Format24bppRgb)
Dim g As Graphics = Graphics.FromImage(imgFullSize)
g.DrawImage(imgFullSizeTemp, 0, 0, imgFullSizeTemp.Width, imgFullSizeTemp.Height)
g.Dispose()
imgFullSizeTemp.Dispose()
response.write (" >>> Converted!<BR><BR>")
Dim clone as new Bitmap(imgFullSize)
clone.Save(imageName, ImageFormat.Jpeg)
End Sub
</script>

Nathan Tuggy
- 2,237
- 27
- 30
- 38

Niente0
- 504
- 3
- 11