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

Real Picture Frame?

0 views
Skip to first unread message

Scenes

unread,
Dec 9, 2004, 10:39:20 AM12/9/04
to
I would like to be able to create a frame around a picture using an
image of a short length of an actual picture framing moulding.

I was hoping to be able to tile the image of the frame around the
rectangular picture (possibly overlapping and blending in some way to
soften the join between each tile), and have the corners mitered (cut
at 45 degrees).

This is my first graphics project and I have not got a clue where to
begin. Any help would be very much appreciated.

Peter Below (TeamB)

unread,
Dec 9, 2004, 2:21:16 PM12/9/04
to

To copy a bitmap to a non-rectangular area of another bitmap (or some
canvas) you need to work with a cliping region. For this you need a
couple of API functions. CreatePolygonRgn will create a Windows region
from an array of points defining a polygon. You can use that to create
a trapezoidal region for a segment of the frame (with a bit of
trigonometry thrown in to calculate the points). You can then select
this region as the cliping region for a canvas (SelectClipRgn) and
finally tile your frame bitmap onto the canvas using the Canvas.Draw
method. Any parts outside the cliping region will be cut off. Repeat
for all four frame sections. The inside part is easier since it is
rectangular from the start, so you just need to clear the cliping
region (SelectClipRgn(canvas.handle, 0)) and then use Canvas.Draw or
StretchDraw to draw the image inside the frame. Don't forget to delete
your regions once you are done with them (Windows.DeleteObject),
otherwise you will have a GDI resource leak that have dire
consequences, especially on Win9x platforms.

Regions are quite flexible, they can even contain curves etc., so you
could even deal with ornamental frames that do not have a rectangular
hole for the image. Such regions are a bit more complex to create,
though. Look at the API functions for GDI pathes, BeginPath, ClosePath,
EndPath, PathToRegion. They allow you to create a complex path through
a sequence of drawing operations (which won't actually draw anything
unless you call FillPath or StrokePath).

--
Peter Below (TeamB)
Use the newsgroup archives :
http://www.mers.com/searchsite.html
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be


Ben Hochstrasser

unread,
Dec 9, 2004, 3:05:09 PM12/9/04
to
Scenes wrote:

> This is my first graphics project and I have not got a clue where to
> begin. Any help would be very much appreciated.

First of all, you probably need a corner piece (crafted in a different part
of the application plus a side piece (that can be tiled to fill the gaps
between the rotated corner pieces). The result would be a bitmap showing an
empty frame. After that, simply canvas.draw() the photo into the middle of
the "frame" bitmap.

To create a corner piece, there's Peter's region and clipping way, or you
could create a monochrome (ie black) mask that has the shape of one of the
pieces you want to "cut out". Then combine source bitmap and mask so that
only the pixels that were set in both mask and bitmap will be drawn. (This
works with non-monochrome masks too; you an even combine a background and a
foreground bitmap using a suitable mask.)

--
Ben

Scenes

unread,
Dec 21, 2004, 12:41:54 PM12/21/04
to
Thanks guys,

This is a great start and exactly the kind of help I'm looking for.

John

0 new messages