Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Rasterize off by one pixel

4 views
Skip to first unread message

swiftset

unread,
Jun 5, 2009, 3:58:40 PM6/5/09
to
I'm trying to make a 100x100 pixel image using Rasterize, as follows,
where n=100

Rasterize[
Graphics[Rectangle[{0,0}, {1,1}],
PlotRange->{{0,2},{0,2}}],
"Image",
RasterSize->{n,n}
]

when I check the resulting image using ImageDimensions, the size is
100x101. If I say size {n,n/2}, then the image is 100x51 instead of
100x50.

Any ideas what causes this and how to fix it? Thanks.

Jens-Peer Kuska

unread,
Jun 6, 2009, 3:48:25 AM6/6/09
to
Hi,

With[{n = 100},
img = Rasterize[
Graphics[Rectangle[{0, 0}, {1, 1}], PlotRange -> {{0, 2}, {0, 2}},
PlotRangePadding -> None, AspectRatio -> Automatic,
ImagePadding -> None], "Image", ImageSize -> {n, n}]
]

?

Regards
Jens

leh...@gmail.com

unread,
Jun 7, 2009, 5:02:36 AM6/7/09
to

Hello,
The simplest solution is:

n=100;
Image[Graphics[Rectangle[{0, 0}, {1, 1}],
PlotRange -> {{0, 2}, {0, 2}}, ImageSize -> {n, n}]]

Sjoerd C. de Vries

unread,
Jun 8, 2009, 1:44:51 AM6/8/09
to
For n<15 this has still problems. See this plot:

DiscretePlot[
img = Rasterize[
Graphics[Rectangle[{0, 0}, {1, 1}], PlotRange -> {{0, 1}, {0, 1}},


PlotRangePadding -> None, AspectRatio -> Automatic,

ImagePadding -> None], "Image", ImageSize -> {n, n}] //
ImageDimensions, {n, 100}]

Cheers -- Sjoerd

On Jun 6, 9:48 am, Jens-Peer Kuska <ku...@informatik.uni-leipzig.de>
wrote:


> Hi,
>
> With[{n = 100},
> img = Rasterize[

> Graphics[Rectangle[{0, 0}, {1, 1}], PlotRange -> {{0, 2}, {0, 2}}=

0 new messages