I'm making an application to change the rgb value to cmyk
But strangely, the price is wrong
What's the problem?
Hi
Colour conversions cannot be 100% accurate. Try my code:
Procedure.s PfRgb2Cmyk(iRed.i, iGrn.i, iBlu.i)
;#--------------------------------------------
;Cyan, Magenta, Yellow, Black
Protected dMin_CMY.d, dCyan.d, dMgta.d, dYllw.d, dblcK.d
Protected sColour.s, sMin_CMY.s
If(iRed = 0) And (iGrn = 0) And (iBlu = 0)
;Colour is Black
sColour = "CMYK(0.000, 0.000, 0.000, 1.000)"
ElseIf(iRed = 255) And (iGrn = 255) And (iBlu = 255)
;Colour is White
sColour = "CMYK(0.000, 0.000, 0.000, 0.000)"
Else
;RGB to CMY range 0, 1
dCyan = (1 - (iRed / 255))
dMgta = (1 - (iGrn / 255))
dYllw = (1 - (iBlu / 255))
;Extract K
sMin_CMY = PfMinMax(dCyan, dMgta, dYllw)
dMin_CMY = ValD(StringField(sMin_CMY, 3, "|"))
dCyan = ((dCyan - dMin_CMY) / (1 - dMin_CMY))
dMgta = ((dMgta - dMin_CMY) / (1 - dMin_CMY))
dYllw = ((dYllw - dMin_CMY) / (1 - dMin_CMY))
dblcK = dMin_CMY
If(dCyan < 0) : dCyan = 0.00000 : EndIf
If(dMgta < 0) : dMgta = 0.00000 : EndIf
If(dYllw < 0) : dYllw = 0.00000 : EndIf
If(dblcK < 0) : dblcK = 0.00000 : EndIf
sColour = "CMYK(" + StrD(dCyan, 3) + "," + StrD(dMgta, 3) + "," + StrD(dYllw, 3) + "," + StrD(dblcK, 3) + ")"
EndIf
ProcedureReturn(sColour)
EndProcedure
thank you for the information
But how to apply this code to App Inventor?
don't know
....yes, thinking about it, you need to be familiar with a text-based programming language in order to follow it. That code is written in Pure Basic, which is a sort of rich C.
However, what you can see is that if the RGB value is extreme, it's best to handle that separately rather than use the algorithm. For example we know RGB(0,0,0) is solid Black, so we can just return CMYK(0.000, 0.000, 0.000, 1.000) - if we used the algorithm, the colour would be slightly grey. Same rule applies to Solid White.
You used 225 instead of 255.