Home/ Reference/ Bitmap

shape.ConvertToBitmap(Resolution)

Turns a vector object into a bitmap (export and reimport, essentially). You lose the vector advantage and it can't be undone — save a copy first.

Signature

shape.ConvertToBitmap(Resolution)

Notes

Turns a vector object into a bitmap (export and reimport, essentially). You lose the vector advantage and it can't be undone — save a copy first.

Python example (runnable)

Requires pywin32. The example assumes app / doc / page / layer are already connected. See Connection & Init
Python
shape = app.ActiveSelectionRange(1)
print("Type before: ", shape.Type)                     # may report 3 curve or 6 text

try:
    shape.ConvertToBitmap(300)                      # 300 dpi
    print("Type after: ", shape.Type)                  # 5 = bitmap
except Exception as e:
    print("ConvertToBitmap failed: ", e)

It burns vectors into pixels, in one step

After ConvertToCurves the object is still vector: the glyphs have become outlines and it scales forever. ConvertToBitmap is something else entirely. It rasterises the shape — text, curve, an entire group — into a bitmap object. At the moment the conversion finishes, the vector data is gone, and from then on any enlargement shows pixel grid.

So the two operations are irreversibly different in kind. Converting to curves loses the text attributes; the shape is still a shape. Converting to bitmap loses the vector nature; the artwork is now bound to a resolution. Pick the wrong one and the cost shows up at prepress.

One argument: the resolution

Python
s.ConvertToBitmap(300)      # 300 dpi

It takes a dpi value, which sets how fine a grid is used when sampling: give it 300 and a shape's current size is converted to pixels at 300dpi. The same 100mm-wide shape becomes roughly 1181px at 300dpi and roughly 283px at 72dpi.

Once set, this cannot be undone. Too low and any later enlargement is interpolated mush; too high and the file size climbs steeply. Start at 300 for print; 72 to 150 is plenty for screen.

The old reference is basically void afterwards

This is the step people miss. The conversion replaces the object itself, so a variable captured beforehand may raise or return a stale value when read afterwards. The safe move is to re-fetch:

Python
import time

s = doc.ActiveSelectionRange(1)
print("before:", s.Type)          # 6 = text, 3 = curve, 7 = group

s.ConvertToBitmap(300)
time.sleep(0.3)                   # let it settle before reading back

s = doc.ActiveSelectionRange(1)   # re-fetch, do not reuse the old reference
print("after :", s.Type)          # 5 = bitmap

The sleep is not decoration. Rasterising is heavy work, and reading the type immediately can return the pre-conversion value. This is the same family of problem as the stale reference after converting, except quieter — converting to curves at least raises visibly, while this one sometimes just gives you the wrong number.

When you actually need it

In the other direction, do not reach for it casually on artwork headed for print. When the client asks to change one character's size the next day, a bitmap cannot do it; the block has to be rebuilt.

Side effects: size and sharpness

A 20KB vector logo converted at 300dpi can become hundreds of KB or several MB. The reason is structural: bitmaps store pixels, vectors store formulas, so complexity and file size relate in opposite directions. Estimate the total before a batch conversion rather than letting the disk make that decision for you.

Sharpness is subtler. A bitmap blurs once enlarged past its native pixel density; a vector does not. The same file looks identical on screen and obviously different printed on an A0 poster. Set the resolution for the largest output size you will ever need, at 300dpi — that is the cheapest insurance available.

How it divides work with the other two routes

Only the last of the three leaves the document alone. The first two both modify it, irreversibly. Save first.

Complete example: convert and verify

Python
import time

def to_bitmap(shape, dpi=300):
    before = shape.Type
    shape.ConvertToBitmap(dpi)
    time.sleep(0.3)

    s = doc.ActiveSelectionRange(1)   # the old reference is no longer trustworthy
    if s.Type != 5:
        raise RuntimeError(f"expected a bitmap, got type {s.Type}")
    return s, before

s, was = to_bitmap(doc.ActiveSelectionRange(1), 300)
print(f"type {was} -> {s.Type}, {s.Bitmap.SizeWidth}x{s.Bitmap.SizeHeight} px")

The verification step earns its place: occasionally the conversion "does nothing" and the object type is unchanged. Without the check you carry on with what you believe is a bitmap but is still a vector, and the error surfaces much later.

About this section: Bitmap

Bitmap — raster image handling.

Other entries in this section