.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

BitmapImage detect image size before calling EndInit()

Posted By:      Posted Date: September 13, 2010    Points: 0   Category :WPF
Hi, I'm using the following converter to create the thumbnails images: public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { try { BitmapImage bi = new BitmapImage(); string FilePath = value as string; if (null != FilePath) { bi.BeginInit(); bi.DecodePixelHeight = 80; bi.CacheOption = BitmapCacheOption.OnLoad; bi.CreateOptions = BitmapCreateOptions.DelayCreation; bi.UriSource = new Uri(FilePath); bi.EndInit(); } if (bi.CanFreeze) { bi.Freeze(); } return bi; } catch { return DependencyProperty.UnsetValue; } }   The problem is that I want to detect the image file height before generating the actual BitmapImage. In other words I need something like this:   bi.BeginInit(); if(bi.Height > 80) { bi.DecodePixelHeight = 80; } bi.CacheOption = BitmapCacheOption.OnLoad; bi.CreateOptions = BitmapCreateOptions.DelayCreation; bi.UriSource = new Uri(FilePath); bi.EndInit();   Which of cause can't be done before the EndInit() has been called. Is there is any other solution that doesn’t require creating some sort of Image class and loading the image file into it. The problem is that I'm expecting to hav

View Complete Post

More Related Resource Links

Reduce Image Size


How to reduce the image weight using asp.net, without lose of image quality and image pixels. For example i have an image with the size of 4 MB (3024*2045), so how to reduce the image weight ie 4 MB to 1 MB without lose quality in the same pixels ie(3024 * 2045) using asp.net.

Detect Browser Screen Size??


Hi Everyone,  I need to detect the size of the user's screen for mobile devices (especially the BlackBerry). I've read a lot of pages that seem to refer me to the Request.Browser object, but I'm finding that this object doesn't have the correct values. For example, I have a BlackBerry and when I use the Request.Browser to get the screen size, it tells me it is 640x480. Well, I know it's not that big since an image of 300px wide just barely fits. Also, when I run on my desktop browser, it also says my screen is 640x480. I can assure you, it is not 640x480! ha!

  How does anyone reliably get the browser's screen size?? Do I have to revert to some kind of JavaScript? If so, where can I read more about it? Will it be any more reliable? Someone must have an idea about this. Thanks in advance!!

AsyncFileUpload: Throw Error on image size


I have an AsyncFilUpload that is used to upload  to my site. On the server side I have code that checks the width and height of the image and will only save the image if it is within the limits buit I can't figure out how to get the AsyncFileUpload control to show an error when this happens. Can anyone give me any pointers?


Get real image size in centimeters

Hi, Im new in c# , I have an image in picturebox and draw a line connecting within two coordinates points x1, y1 and x2, y2. I wonder if there is any way of calculating the size of the line in centimeters. If i can have an example i will thank. Thanks ..  ed

size of dropped image

hi!! i have a drag and drop handle on a canvas which displays a image on canvas when dropped a file on it: private void DropHandle(object sender, System.Windows.DragEventArgs e) { string[] arrstrFileNames = e.Data.GetData(DataFormats.FileDrop, true) as string[]; if (first) { MenuItem mnu1 = new MenuItem(); mnu1.Header = "Rotate"; mnu1.Click += new RoutedEventHandler(Rotate_Click); MenuItem mnu2 = new MenuItem(); mnu2.Click += new RoutedEventHandler(Crop_Click); mnu2.Header = "Crop"; MenuItem mnu3 = new MenuItem(); mnu3.Header = "Delete"; mnu3.Click += new RoutedEventHandler(Delete_Click); mnu.Items.Add(mnu1); mnu.Items.Add(mnu2); mnu.Items.Add(mnu3); } if (arrstrFileNames == null || arrstrFileNames.Length < 1) return; try { BitmapImage bmp = new BitmapImage(); bmp.BeginInit(); bmp.UriSource = new Uri("file:///" + arrstrFileNames[0].Replace("\\", "/")); bmp.EndInit(); Image img = new Image(); img.Source = bmp; img.Width = 300; img.Height = 300; RotateTransform rt = new RotateTransform(); img.LayoutTransform = rt; if(first==true) img.ContextMenu = mnu; first = false; assig

setting inline image size with css?

I have an inline image in the header of a page that's height is being set with CSS.  The actual height of the image is slightly taller than what it's currently set to with css.  I like doing this this way because it was easier to get the image to the right size.  It avoided multiple attempts in photoshop.Is it a bad idea to set the height of an image this way?   I'm only concerned with the major modern browsers.  Are there any side effects of this that I should be aware of?

create polyline size relative to image clicked



i am creating a path geometry using polyline:


 System.Windows.Point Point1 = new System.Windows.Point(50, 10);
      System.Windows.Point Point2 = new System.Windows.Point(200, 10);
      System.Windows.Point Point3 = new System.Windows.Point(200, 100);
      System.Windows.Point Point4 = new System.Windows.Point(10, 100);
      System.Windows.Point Point5 = new System.Windows.Point(10, 50);
      System.Windows.Point Point6 = new System.Windows.Point(50, 10);
      PointCollection polygonPoints = new PointCollection();
      yellowPolyline.Points = polygonPoints;

this is a rectangle which is clipped from top-left,

actually i want to create dynamically a polyline whose size is relative to the image i click on the canvas 

and then apply than clip that image using that polyline,,so that the image looks clipped from top-left

how can

Detect Width and Height of .jpg image



I have an image on this path that I first check if it exists. If it exists I wonder what the method is to get width and height of this image ?

            if (File.Exists(Server.MapPath("Images\\Pic1.JPG")))
		    //How to get the Width and Height of this JPG Image ?


Controlling Page Image Size / Scale

I have created a custom master page for a WSS 3.0 site and all is working well except for the fact that I want to use the default page images that are provided, but they are too wide for the area available.  I have tried setting the table width but the width of the image seems to override that, so I would like to know if there is a way I can control the size (or better yet the scale) of the page image when it is displayed in order to have it fit within the area I have on the custom master page.

Thanks in advance,

Converting an Image/BitmapImage object into Byte Array and vice versa

Hi,  I have an requirement of developing an application (WPF) that recevies image object from WCF service.

my approch is to convert the image object into stream of bytes (Byte array) in WCF part and then send to  client application. Then client application converts the byte array back to image object.

I am not able to find right sample for my approach.

would you give me guidance and would be gr8 if you provide some samples.


Set the image size


 Is it possible to set the max size on a image in a div by code? If it does, how do I do it?

Reducing image file size without losing quality


hi frends,

           I need help(code) to reduce the image file size..

                         Thanks in advance...

Resize image and get new byte size without saving it


Hi Guys,

I'm making an application that needs to be able to take a user specified image file and upload it into a database that only accepts images of 10 KB or less. So I want to let the user select an image and then have the option of resizing it and if possible also decreasing the quality - I'm sure I can figure out how to do both of these things on my own but the thing I'm not sure about is how I can tell what size the resulting image will be without actually writing it to disk. I thought the SourceStream property of the BitmapSource class would be useful but when I try to access it I just get told that the stream has been closed. Any ideas?




My website: www.cjwdev.co.uk My blog: cjwdev.wordpress.com

Code to detect monitor size

How to detect monitor size(i.e. 15 inch, 18 inch, 24 inch, etc) from C#.Net 2005 Windows Application.

.NET converts pixels to points and creates a wrong image size


I have an image of size 144 pixels (I measured the image size using both irfanView and Photoshop).

However, when opened in a window using the following xaml, the image's width, measured both by the ActualWidth parameter and by the same graphic software, is 192 pixels.

It turns out that 141 points = 192 pixels (as 1pt=1.33px).

So it seems like .Net opens the image, measure it size in pixels and draws the image with the same size but in points.

Here is the XAML and code:

  <Window x:Class="test_image_resizing.MainWindow"

How to detect and avoid memory and resources leaks in .NET application

Despite what a lot of people believe, it's easy to introduce memory and resources leaks in .NET applications. The Garbage Collector, or GC for close friends, is not a magician who would completely relieve you from taking care of your memory and resources consumption.

I'll explain in this article why memory leaks exist in .NET and how to avoid them. Don't worry, I won't focus here on the inner workings of the garbage collector and other advanced characteristics of memory and resources management in .NET.

Reduce ASP.NET Page size and complexity using JQuery

This is my first post on asp.net blog. ASP.NET Ajax and JQuery are two different ajax framework. In this post I will show, how we can enhance gridview using ASP.NET Ajax and JQuery. I also compare the implementation of these frameworks. In next posts i will explain more about JQuery and ASP.NET Ajax and also tell you "How to combine the power of both framework". My Future post will related to ASP.NET and related frameworks.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend