Solved

WPF Border from Image

Posted on 2010-08-19
2
1,047 Views
Last Modified: 2013-11-12
Hi to all,

I am starting a new project that will basically take an image and "frame" the image. We have a framing shop that wants a in store application to help users select the frame they need for their image. WPF seemed to be the best fit for this project.

How would I go about setting a border's "border" based from an image? I was thinking of placing an image inside a border to give the effect of a frame.

Any suggestions would be appreciated on this. If there are any samples that could help me I would appreciate that as well.

We will be using Visual Studio 2010 and .Net 4.0

Thanks
0
Comment
Question by:ALawrence007
2 Comments
 
LVL 27

Accepted Solution

by:
MikeToole earned 500 total points
ID: 33483578
There's no need for a border, just superimpose the picture on the frame, setting the margin of the picture image to the width of the frame's sides.

            <Grid>
                <Image Source="...TheFrame.jpg"/>
                <Image  Source="...ThePicture.jpg" Margin="40"/>
            </Grid>

You'd use data binding to set the source, probably setting the frame's source to the active item on a list box, which in turn would show the images of the frames to choose from.

There are tweaks for performance - the whole original image is loaded, then resized when you do it this way, the attached code from Microsoft documentation shows how to reduce the load.
<Image Width="200">

  <Image.Source>

    <!-- To save significant application memory, set the DecodePixelWidth or  

     DecodePixelHeight of the BitmapImage value of the image source to the desired 

     height and width of the rendered image. If you don't do this, the application will 

     cache the image as though it were rendered as its normal size rather then just 

     the size that is displayed. -->

    <!-- Note: In order to preserve aspect ratio, only set either DecodePixelWidth

         or DecodePixelHeight but not both. -->

    <BitmapImage DecodePixelWidth="200"  

     UriSource="C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Water Lilies.jpg" />

  </Image.Source>

</Image>

Open in new window

0
 

Author Closing Comment

by:ALawrence007
ID: 33487050
Just what I was looking for!!! Thanks Mike!!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now