저는 Android에서 색상 선택 도구를 만들려고 노력하고 있습니다. 그러나 내가 잘못하고있는 것을 잘못 이해하고 있습니다. ImageView가 있고이 이미지를 비트 맵으로 디코딩합니다. 비트 맵에서 GetPixel()
메서드를 사용하고 있지만이 시점에서 뭔가 잘못하고 있다고 생각합니다. 누군가 내가 뭘 잘못하고 있는지 말할 수 있습니까? 그래서 아마 해상도가 문제가,Xamarin이 비트 맵에서 잘못된 색상을 얻었습니다.
내가 Z1 컴팩트에서 테스트하고 있습니다 (720x1280 해상도, 안드로이드 5.1.1), 그리고 그림은 750x300입니다 : 여기에 내가 사용하고있는 이미지입니다?
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