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

Not very beautiful, but working:

 im = ImageResize[Image[Graphics[Rectangle[{0, 0}]]], {10, 20}];
$\endgroup$
  • $\begingroup$ Works ! Thanks ! $\endgroup$ – james Aug 8 '18 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, privacy policy and cookie policy

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