[Gambas-user] Drawing

Timothy Marshal-Nichols timothy.marshal-nichols at ...247...
Mon Apr 24 18:57:08 CEST 2006


This example shows how to print an image centred on the page. In includes
code to scale an image for the printer resolution. If the image is the to
large for the printer height or width resizes it to fit on the page -
keeping the aspect ratio.

You will need something like this only with a drawing.

PRIVATE SUB PrintImage(img AS Image)
  DIM imageToPrint AS Image
  DIM imageWidth AS Integer
  DIM imageHeight AS Integer
  DIM scaleIsotropic AS Float
  ' Dispaly printer dialog
  IF Printer.Setup() THEN RETURN
  INC Application.Busy
  ' Get image size for the printer resolution
  imageWidth = (img.Width * Printer.Resolution) / Desktop.Resolution
  imageHeight = (img.Height * Printer.Resolution) / Desktop.Resolution
  ' Adjust image size if it does not fit on the printer page
  IF imageWidth > Printer.Width OR imageHeight > Printer.Height THEN
    ' Scale Isotropic, keep aspect ratio of the image
    scaleIsotropic = Min(Printer.Width / imageWidth, Printer.Height /
imageHeight)
    imageWidth *= scaleIsotropic
    imageHeight *= scaleIsotropic
  END IF
  'PRINT "Width: " & imageToPrint, Printer.Width
  'PRINT "Height: " & imageToPrint, Printer.Height
  ' Scale image
  imageToPrint = img.Stretch(imageWidth, imageHeight, TRUE)
  ' Draw image centered on printer page
  Draw.Begin(Printer)
  Draw.Image(imageToPrint, (Printer.Width - imageWidth) / 2,
(Printer.Height - imageHeight) / 2)
  Draw.End
  DEC Application.Busy
END


Thanks

8-{)} Timothy Marshal-Nichols
<mailto: timothy.marshal-nichols at ...247...>


-----Original Message-----
From: gambas-user-admin at lists.sourceforge.net
[mailto:gambas-user-admin at lists.sourceforge.net]On Behalf Of javier
romero
Sent: Monday, 24 April 2006 14:37
To: gambas-user at lists.sourceforge.net
Subject: RE: Re: [Gambas-user] Drawing


Ok, thanks, its works but the print is very small, i try scaling with this:

   draw.Begin(printer)
     draw.drawing(p1,350,350, Printer.Width, Printer.Height)
   draw.End
   but dosent works the print is the same, little, i try then with

   draw.Begin(printer)
     draw.drawing(p1,350,350, p1.Width, p1.Height)
   draw.End
and the same, very little, in both dont change

How i scale?

sorry about my very bad english

Regards
Javier
----------------------------------------
> From: christian.faurebouvard at ...357...
> To: gambas-user at lists.sourceforge.net
> Subject: Re: [Gambas-user] Drawing
> Date: Sat, 22 Apr 2006 17:50:15 -0400
>
> El Viernes 21 Abril 2006 09:48, javier romero escribió:
> > PUBLIC p1 AS Drawing
> > PUBLIC pag AS DrawingArea
> >
> > PUBLIC SUB _new()
> >     p1 = NEW Drawing
> >     draw.Begin(p1)
> >       draw.Text("Hello", 0, 0)
> >     draw.End
> >
> > END
> >
> > PUBLIC SUB Form_Open()
> >
> > pag = NEW DrawingArea(sv1)
> >
> >   pag.Cached = TRUE
> >   pag.Clear
> >   pag.BackColor = color.White
> >   pag.Width = printer.Width
> >   pag.Height = printer.Height
> >   pag.Border = 1
> >   draw.Begin(pag)
> >     draw.Drawing(p1, 0, 0)
> >   draw.End
> > ' This works OK
> >   pag.Visible = TRUE
> >
> > END
> >
> > PUBLIC SUB Button1_Click()
> >
> >   draw.Begin(printer)
> >     draw.drawing(p1,0,0, pag.Width, pag.Height)
> >   draw.End
> > ' This doesn't works
> > END
>
> Hi Javier,
>
> Some printers can't print in (0,0)
> Try
>  draw.drawing(p1, 350, 350)
>
> it work, but very small, need to be scaled.
>
> Regards,
> Christian
>
>
> -------------------------------------------------------
> Using Tomcat but need to do more? Need to support web services, security?
> Get stuff done quickly with pre-integrated technology to make your job
easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> http://sel.as-us.falkag.net/sel?cmd=k&kid0709&bid&3057&dat1642
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user

_________________________________________________________________
Descarga gratis la Barra de Herramientas de MSN
http://www.msn.es/usuario/busqueda/barra?XAPID=2031&DI=1055&SU=http%3A//www.
hotmail.com&HL=LINKTAG1OPENINGTEXT_MSNBH

-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job
easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=k&kid0709&bid&3057&dat1642
_______________________________________________
Gambas-user mailing list
Gambas-user at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user






More information about the User mailing list