Bitmap Colors & Editing in CMYK

Nathan Sokalski 4,116 Reputation points
2023-02-06T01:33:06.46+00:00

I have a Xamarin.Android app with an Android.Graphics.Bitmap for which I need to view each pixel's color in CMYK (as opposed to RGB). I also need to be able to rotate & crop the Bitmap. I am not extremely familiar with working with graphics & images, and could not seem to find good ways to do these things. Any ideas?

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,291 questions
.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,346 questions
0 comments No comments
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 68,016 Reputation points Microsoft Vendor
    2023-02-06T08:28:49.59+00:00

    Hello,

    I need to view each pixel's color in CMYK (as opposed to RGB)

    If you can get the RGB data, you can convert it to CMYK color,

    double R = R / 255
    double G = G / 255
    double B = B / 255
    
    double K = 1 - Math.Max(R, Math.Max(G, B));
    double C = (1 - R - K) / (1 - K)
    double M = (1 - G - K) / (1 - K)
    double Y = (1 - B - K) / (1 - K)
    

    I also need to be able to rotate & crop the Bitmap.

    For crop the Bitmap, you can ceate a new bitmap , set start cropped postion in X, Y axis and cropped bitmap's width and height.

     public Bitmap CropImage(Bitmap bitmap,int x, int y ,int width, int height)
            {
                Android.Graphics.Bitmap crop = Android.Graphics.Bitmap.CreateBitmap(bitmap, x, y, width, height);
                return crop;
            }
    

    For rotate the bitmap. You can use Matrix to achieve.

            public Bitmap RotateImage(Bitmap image, int width, int height)
            {
                var matrix = new Matrix();
                matrix.PostRotate(90);
                return Bitmap.CreateBitmap(image, 0, 0, image.Width, image.Height, matrix, true);
            }
    

    As note:Avoid duplicate questions

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful