Click here to Skip to main content
15,884,537 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I have a many rectangle in my program which be filled with image. I have done two method:-

1) Get image from outside of solution. Application will create a folder called Images and all the image are put on it. The rectangle ImageSource will link as this
XML
<ImageBrush ImageSource="Images/Background.jpg" />

2) Create a folder on the exe path(debug) and open choose image. The rectangle ImageSource will link as this
XML
<ImageBrush ImageSource="/Mypp;component/bin/Debug/image/background/Background.jpg" />


Both of my method will make my exe become large as the exe will embed the image on it. If I blank the rectangle and use code to memorystream the image from any path, it will take time to load(looks freeze) as on my page, some of it have 40rectangle to be filled. So have any other way to make exe smaller size which the ImageSource can be like
XML
<ImageBrush ImageSource="Debug/image/background/Background.jpg" /> 
I need to be like this because the image must be able to change but keep the filename and extension as same as current file based from user requirement.

So I'm asking anyone who knows the tricks or have some guideline, kindly share with me. Thanks programmer.
Posted

Instead of using Rectangle and ImageBrush, try using Border and Image tag.

Set MaxWidth and MaxHeight properties of the Image tag to specify the maximum width and height supported. Image will be shrink to fit in the size specified.

HTML
<Border Borderbrush="#395984" Borderthickness="2">
  <Image Source="./images/iq.png" MaxHeight="20" MaxWidth="20"></Image>
</Border>
 
Share this answer
 
v3
Comments
Luiey Ichigo 20-May-15 4:35am    
THis code i use and it works perfect. I dont know why when even I set the image stretch to Uniform, it still like rescale the rectangle. WHen using border, it center the image on it. Thanks
You could try making the image file smaller? Reduce resolution, change compression technology etc.
 
Share this answer
 
Comments
Luiey Ichigo 6-May-15 8:16am    
Not the image, but the exe become smaller where image are not embed to the exe but refer to the link which dynamic
Wastedtalent 6-May-15 8:51am    
If you want to avoid the freezing/make the application more responsive whilst loading you could load the images to memory on a separate thread and then once the load is completed notify the main thread to display the images.
Luiey Ichigo 9-May-15 15:47pm    
using background worker?
Wastedtalent 11-May-15 3:41am    
Background worker would be a good way to start with threading.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900