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
Notes
Python example (runnable)
pywin32. The example assumes app / doc / page / layer are already connected.
See Connection & Initshape = 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
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:
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
- An effect only works on bitmaps. Some filters and effects do nothing on vector objects, or render differently from what the UI previewed, and only behave once rasterised.
- The vector is so complex it slows everything down. Thousands of curve nodes on one page makes zooming, dragging and exporting crawl. A high-resolution bitmap eases that considerably, at the cost of editability.
- You need it to look identical everywhere. Rendering vectors across machines can differ subtly in fonts, effects and transparency. Once rasterised, the pixels are fixed and it looks the same for everyone. Common practice for delivery previews.
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
ConvertToCurves— text to outlines, still vector, still scalable. For missing fonts.ConvertToBitmap— rasterise to pixels, bound to a resolution. For effects and file size.ExportBitmap— write a file, document unchanged. For delivering images.
Only the last of the three leaves the document alone. The first two both modify it, irreversibly. Save first.
Complete example: convert and verify
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.
- This section has 8 entries; this is one of them.
- See the full section index: Bitmap
Other entries in this section
- shape.BitmapEntry point to the bitmap sub-object. Check Type == 5 first or access
- bitmap.ResolutionX / ResolutionYHorizontal and vertical resolution in dpi. 300 is the floor for print;
- bitmap.SizeWidth / SizeHeightThe bitmap's size in pixels, not document size. This is how you tell w
- bitmap.ModeColor mode (CMYK, RGB, grayscale, bitmap and so on). The first thing t
- bitmap.Resample(Width, Height, Resolution)Resamples, changing pixel count and resolution. Upscaling invents no d
- bitmap.SaveAs(FileName, Filter)Writes the bitmap out to its own file. Batch image extraction, sending
- shape.ApplyEffectInvert() / ApplyEffectGamma() / ApplyEffectPosterize()Applies color adjustments to a bitmap: invert, gamma, posterize. These