打印的图像占据整个页面的单色

时间:2012-12-11 16:21:03

标签: printing xamarin.ios

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

图像打印出来,但会占据整个页面。如何将图像限制为实际尺寸? (约为200px 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");
                }
            } );
        }

1 个答案:

答案 0 :(得分:0)