私はアンドロイドでカラーピッカーを作ろうとしていますが、私が間違ったことをしていると分かりません。私はImageViewを持っており、このイメージをビットマップにデコードしています。ビットマップではGetPixel()
メソッドを使用していますが、私はこの時点で何か間違っていると思います。誰かが私が間違っていることを伝えることはできますか?ここで私が使用しているイメージがある:Xamarinがビットマップから間違った色を取得しています
ので、多分解像度が問題であり、私は(720x1280解像度、アンドロイド5.1.1)Z1コンパクトでそれをテストしていて、画像が750×300でありますか?
namespace ImageViewTest
{
[Activity(Label = "ImageView", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
int colorPickerWidth = 750, colorPickerHeight = 300, colorBaseHeight = 1184, colorBaseWidth = 720;
float colorPickerScaleWidth = 720/colorBaseWidth, colorPickerScaleHeight = 1184/colorBaseHeight;
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
RelativeLayout rl = FindViewById<RelativeLayout>(Resource.Id.relative);
ImageView colorPanel = new ImageView(this);
colorPanel.SetImageResource(Resource.Drawable.colorPicker);
colorPanel.LayoutParameters = new ViewGroup.LayoutParams(colorPickerWidth, colorPickerHeight);
Bitmap bitmap = BitmapFactory.DecodeResource(this.Resources, Resource.Drawable.colorPicker);
bitmap = Bitmap.CreateBitmap(bitmap);
colorPanel.SetImageBitmap(bitmap);
colorPanel.Touch += (object sender, TouchEventArgs e) =>
{
Console.WriteLine("X:" + (int)e.Event.GetX());
Console.WriteLine("Y:" + (int)e.Event.GetY());
try
{
Color pixel = new Color(bitmap.GetPixel((int)e.Event.GetX(), (int)e.Event.GetY()));
int red = Color.GetRedComponent(pixel), green = Color.GetGreenComponent(pixel), blue = Color.GetBlueComponent(pixel);
Console.WriteLine("R:" + red + " G:" + green + " B:" + blue);
}
catch
{
}
};
rl.AddView(colorPanel);
}
}
}
どちらの色がお好みですか?どの色が得られますか?数字を教えてください! X、Yで始まる – greenapps