我正在使用以下代码在 monotouch 中打印图像(png 文件):
void Print ()
{
UIImage image = myImgView.Image;
NSMutableData data = new NSMutableData();
UIGraphics.BeginPDFContext(data, new RectangleF(new PointF(0,0), image.Size), null);
image.Draw(new RectangleF(0, 0, image.Size.Width, image.Size.Height));
UIGraphics.EndPDFContent();
var printInfo = UIPrintInfo.PrintInfo;
printInfo.JobName = "Test: PDF Print";
var printer = UIPrintInteractionController.SharedPrintController;
printer.PrintInfo = printInfo;
printer.PrintingItem = image; //url;
printer.ShowsPageRange = true;
printer.Present (true, (handler, completed, err) => {
if (!completed && err != null){
Console.WriteLine ("error");
}
} );
}
图像打印出来,但占据了整个页面。如何使其将图像限制为实际大小?(大约为 200 像素 x 200 像素)
编辑:
将我的代码更改为此,但结果仍然相同:
void Print ()
{
UIImage image = myImgView.Image;
NSData data = new NSData();
// var imageRect = new RectangleF (){
// Height = image.Size.Height,
// Width = image.Size.Width,
// Size = image.Size
//
// } ;
var printInfo = UIPrintInfo.PrintInfo;
printInfo.JobName = "Test";
var printer = UIPrintInteractionController.SharedPrintController;
printer.PrintInfo = printInfo;
printer.PrintingItem = data;
printer.PrintFormatter = new UIPrintFormatter(){
MaximumContentWidth = image.Size.Width
} ;
printer.ShowsPageRange = true;
printer.Present (true, (handler, completed, err) => {
if (!completed && err != null) {
Console.WriteLine ("error");
}
} );
}