3
$\begingroup$

I am trying to make an image out of a graphic, which is a rectangle with given size.

However, the dimension of the image do not correspond to the size given to the rectangle:

im = Image[Graphics[Rectangle[{0, 0}, {10, 20}]]];
ImageDimensions[im]

{221, 432}

Anyone knows how to do it ?

$\endgroup$
2
  • 1
    $\begingroup$ im = Image[ Graphics[Rectangle[{0, 0}, {10, 20}], ImageSize -> {10, 20}]]? $\endgroup$
    – kglr
    Commented Aug 8, 2018 at 7:58
  • $\begingroup$ @kglr thanks ! This works. :) $\endgroup$
    – james
    Commented Aug 8, 2018 at 8:05

2 Answers 2

3
$\begingroup$

Not very beautiful, but working:

 im = ImageResize[Image[Graphics[Rectangle[{0, 0}]]], {10, 20}];
$\endgroup$
1
  • $\begingroup$ Works ! Thanks ! $\endgroup$
    – james
    Commented Aug 8, 2018 at 8:04
2
$\begingroup$
im = Image[Graphics[Rectangle[{0, 0}, {10, 20}]], ImageSize -> {10, 20}]; (* or *)
im = Image[Graphics[Rectangle[{0, 0}, {10, 20}], ImageSize -> {10, 20}]];

ImageDimensions[im]

{10, 20}

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.