how can I draw into an existing UIImage using monotouch?
I load an image: UIImage.FromFile("MyImage.png")
Then I want to draw a string and some lines into this image.
Does anyone has a code sample?
Thx
how can I draw into an existing UIImage using monotouch?
I load an image: UIImage.FromFile("MyImage.png")
Then I want to draw a string and some lines into this image.
Does anyone has a code sample?
Thx
Here is a method that does it:
private void drawOnTouch(object data)
{
UITouch touch = data as UITouch;
if (null != touch)
{
UIGraphics.BeginImageContext(this.Image == null ? this.Frame.Size : this.Image.Size);
using (CGContext cont = UIGraphics.GetCurrentContext())
{
if (this.Image != null)
{
cont.TranslateCTM(0f, this.Image.Size.Height);
cont.ScaleCTM(1.0f, -1.0f);
cont.DrawImage(new RectangleF(0f,0f,this.Image.Size.Width, this.Image.Size.Height), this.Image.CGImage);
cont.ScaleCTM(1.0f, -1.0f);
cont.TranslateCTM(0f, -this.Image.Size.Height);
} //end if
PointF lastLocation = touch.PreviousLocationInView(this);
PointF pt = touch.LocationInView(this);
using (CGPath path = new CGPath())
{
cont.SetLineCap(CGLineCap.Round);
cont.SetLineWidth(3);
cont.SetRGBStrokeColor(0, 2, 3, 1);
path.MoveToPoint(lastLocation.X, lastLocation.Y);
path.AddLines(new PointF[] { new PointF(lastLocation.X,
lastLocation.Y),
new PointF(pt.X, pt.Y) });
path.CloseSubpath();
cont.AddPath(path);
cont.DrawPath(CGPathDrawingMode.FillStroke);
this.Image = UIGraphics.GetImageFromCurrentImageContext();
}//end using path
}//end using cont
UIGraphics.EndImageContext();
this.SetNeedsDisplay();
}//end if
}//end void drawOnTouch
If you place this method in a subclass of UIImageView and call it from TouchesBegan and TouchesMoved, when you touch the screen it will draw on the image.
I am coding an iPhone application where images are transferred from one iPhone to another using Bluetooth. How do I archive an image and send it to another iPhone, then un-archive the image back? ...
Is it better to have a PNG, say 320px x 44px and display it once, or to have a PNG that is 320px x 4px and use [UIColor colorWithPatternImage:]? I know that the iPhone handles PNGs well and ...
How do you download an image and turn it into a UIImage?
If i do the following it saves fine: - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)selectedImage editingInfo:(NSDictionary *)editingInfo { box = (...
Is it possible to read the name of an UIImageView s UIImage that s presently stored in the UIImageView? I was hoping you could do something kind of like this, but haven t figured it out. NSString *...
I ve been drawing custom table cells (using the samples from apple as a base) and have now come to having to do a cell which displays an image from a URL - each cell would have a different image (...
我对阵列和在我愿意帮助的观点之间传递形象存在问题!
I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...