I’m attempting to attract textual content and get the (x,y)s of the textual content.
I’ll set the background to (R=0,B=0,G=0) and set the textual content Coloration to (R=255,G=255,B=255).
and I wish to know which pixel is (R=255,G=255,B=255).
I attempted a number of strategies.
UIGraphics.BeginImageContext(new CGSize(309, 60));
utilizing (var gra = UIGraphics.GetCurrentContext())
{
gra.SetLineWidth(1);
var font = UIFont.SystemFontOfSize(13);
UIGraphics.PushContext(gra);
gra.SaveState();
var attributedString = new NSAttributedString("这是一个文本", new CTStringAttributes
{
Font = new CTFont(font.Title, 13),
ForegroundColor = UIColor.Purple.CGColor,
StrokeColor = UIColor.FromRGB(255, 255, 255).CGColor
});
attributedString.DrawString(new CGRect(0, 0, 309, 60));
gra.RestoreState();
UIGraphics.PopContext();
var imgData= gra.AsBitmapContext().Knowledge;
}
however all of the imgData’s pixel is #000000
there isn’t any (R=255,G=255,B=255)pixel.
if I add gra.SetStrokeColor(UIColor.FromRGB(255,255,255).CGColor);
the all pixels will change into (R=255,G=255,B=255).
I’ve tried to make use of glyph to attract the textual content however I acquired the identical consequence.
how one can get the pixels?
I’ll use this code :
width = (int)gra.AsBitmapContext().Width;
peak = (int)gra.AsBitmapContext().Top;
bytesPerPixel = (int)gra.AsBitmapContext().BytesPerRow / width;
bytesPerRow = (int)gra.AsBitmapContext().BytesPerRow;
int i = (bytesPerRow * y) + (x * bytesPerPixel);
var purple = Marshal.ReadByte(uncooked) / 255.0f;
var inexperienced = Marshal.ReadByte(uncooked + 1) / 255.0f;
var blue = Marshal.ReadByte(uncooked + 2) / 255.0f;