Reputation: 61
I have created a .net assembly file from the MATLAB and used it in c# windows and c# web application and its working fine. Now I want to use this assembly file in xamarin but I am getting the error. C# code should work in xamarin too. isn't it??
In windows when i tried to fetch the r,g and b channels of image its working fine but when i am trying to do the same thing in xamarin it is giving an error. windows code is as :
int i, j;
Bitmap image = (Bitmap)pictureBox1.Image;
int width = image.Width;
int height = image.Height;
Bitmap processed_image = new Bitmap(width, height);
try
{
byte[,,] rgb = new byte[3, height, width];
for (i = 0; i < height; i++)
{
for (j = 0; j < width; j++)
{
rgb[0, i, j] = image.GetPixel(j, i).R;
rgb[1, i, j] = image.GetPixel(j, i).G;
rgb[2, i, j] = image.GetPixel(j, i).B;
}
}
MWNumericArray narr = new MWNumericArray();
narr = rgb;
Salt obj = new Salt();
MWArray u = obj.classification(narr);
label1.Text = u.ToString();
// MessageBox.Show(u.ToString());
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
and the xamarin code is as:
int i, j;
Bitmap image = bitmapimage;// bitmapimage the image (either taken from gallery or captured using camera)
int width = image.Width;
int height = image.Height;
byte[,,] rgb = new byte[3, height, width];
for (i = 0; i < height; i++)
{
for (j = 0; j < width; j++)
{
rgb[0, i, j] = image.GetPixel(j, i).R;
rgb[1, i, j] = image.GetPixel(j, i).G;
rgb[2, i, j] = image.GetPixel(j, i).B;
}
}
MWNumericArray narr = new MWNumericArray();
narr = rgb;
Salt obj = new Salt();
MWArray u = obj.classification(narr);
textview.SetText(u);
I am getting error in fetching the R, G and B channels.
'int' does not contain a definition for 'R' and no extension method 'R' accepting a first argument of type 'int' could be found (are you missing a using directive or an assembly reference?)
Please help me to solve this error. Will be really great full. Thanks.
Upvotes: 0
Views: 83
Reputation: 2327
It seems to me that you are using Android.Graphics.Bitmap
. The GetPixel
method of this object returns an int
that should be converted to Android.Graphics.Color
. Change your code to this:
var color = new Android.Graphics.Color(image.GetPixel(j, i));
rgb[0, i, j] = color.R;
rgb[1, i, j] = color.G;
rgb[2, i, j] = color.B;
Also, as a side note, GetPixel
is slow, very slow. I suggest working with the raw binary data using Android.Graphics.Bitmap.CopyPixelsToBuffer()
method. Read more here:
Upvotes: 1