0

我正在使用以下代码在 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");
                }
            } );
        }
4

1 回答 1

0

我最终使用了自定义 UIPrintPageRenderer 类,如https://github.com/xamarin/monotouch-samples/blob/master/RecipesAndPrinting/RecipePrintPageRenderer.cs所示

于 2012-12-12T13:35:33.620 回答