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

Top 5 Contributors of the Month
Post New Web Links

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

Posted By:      Posted Date: April 10, 2011    Points: 0   Category :JQuery

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"

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.

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

Logfile size wrong - SMO lies!!

I'm running SMO from Powershell against a SQL 2005 instance and generally issue the following query (with the results shown below): c:\> $ss = New-Object "Microsoft.SqlServer.Management.SMO.Server" "myhost\myinst" c:\> $ss.databases["tempdb"].logfiles[0].Size 65536 If log into that server with SQL Server Management Studio and click on Properties for tempdb, select files, the Size field is shown as 64 (M) However!! if I issue the query below in SSMS, I get a different result.  grr..... sp_helpdb tempdb name fileid filename filegroup size maxsize growth usage templog 2 T:\data_01\\templog.ldf NULL 331904 KB Unlimited 10% log only so what happens is at some point I try to issue something like: ALTER DATABASE [tempdb] MODIFY FILE(NAME='templog',SIZE=112875KB) Msg 5039, Level 16, State 1, Line 1 MODIFY FILE failed. Specified size is less than current size. which obviously fails since my measurement of file size was errorneous. this is really not good. thoughts anyone? p.s. incidentally, if I look at the actual file, its size is correctly stated by sp_helpdb, so SMO is wrong!!

Why Image.save creates a black image

Hello, I am trying to create a screenshot, here is the code, it creates a complete black image.Thanks for any help. Public Function CaptureWindow(ByVal handle As IntPtr) As Image               ' get te hDC of the target window               Dim hdcSrc As IntPtr = User32.GetWindowDC(handle)               ' get the size               Dim windowRect As New User32.RECT()               User32.GetWindowRect(handle, windowRect)               Dim width As Integer = windowRect.right - windowRect.left               Dim height As Integer = windowRect.bottom - windowRect.top               ' create a device c

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?

BitmapImage detect image size before calling EndInit()

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

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

get points of image enter and leave


i have image on my canvas ,,,when i flick my mouse over the image,how can i get the points where the mouse entered and left the image

when the image has some rotate transform angle


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,

Image has wrong Image.PixelFormat on Windows 7, not on XP


Loading an image using System.Drawing.Image.FromFile and then examining the pixelformat - on Windows XP x64 (or x86) the format is a valid value such as PixelFormat24bppRGB but on Windows 7 (x64 or x86) the value returned is 8207, which is not a member of the PixelFormat enumeration.

This problem occurs using .NET framework 3.5 and 4.0

The code used is:

using System;
using System.Drawing;

public class itype {

    public static void Main( string[] args ) {

        Image image = Image.FromFile( args[0] );

        Console.WriteLine( "pixelformat of " + args[0] +
                       " = " + image.PixelFormat );

An image which shows this problem can be downloaded from http://www.xmlpdf.com/images/test.jpg


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

"Smushed" pixels / fuzzy image (even with bitmap class or nearestneighbor)


hi all--

we're having myriad problems with artifacts and other video issues, on three separate computers and three different video cards (2 ATI, 1 NVIDIA).

one of the main issues we're having is that there are certain times when pixels in an image turn fuzzy, even with RenderOptions.BitmapScalingMode="NearestNeighbor" and/or RenderOptions.EdgeMode="Aliased" and/or using the Bitmap class. i've also tried combinations of snapstodevicepixels and uselayoutrounding. 


  • the first picture (a screenshot, enlarged) shows what it (an image in a scatterviewitem, surface touch beta for win7) looks like with BitmapScalingMode set to HighQuality -- as expected, it's fuzzy

  • the second picture (also a screenshot) shows what it looks like when set to NearestNeighbor. looks great, right?

the code for writing a image from the pixels generated...


dear sir/madam,

    i have written a code in asp.net to read an image from file uploader,,from this image i have extracted RGB values(for each pixel)...now i have to write a image using this RGB values itself ,so that the image will be same as image i have read...i have writurn the code but i am not getting the image..please help me in writing this image..please

public partial class _Default : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
        if (!IsPostBack)
            Image1.Visible = false;
            Image2.Visible = false;
            Label1.Visible = false;
            Label2.Visible = false;

    protected void Button1_Click(object sender, EventArgs e)  //to read imag e and extract RGB

        Image1.Visible = true;

        String filename = null;
        string path = null;
        if (FileUpload1.HasFile)
            filename = FileUpload1.FileName.ToString();
            path = "~/image/" + filename;

        String[] getExt = filename.Split('.');
        Label2.Text = getExt[1];
        Image1.ImageUrl = "~/image/" + filename;

        System.Drawing.Image imgs = System.Drawing.Image.FromFile(
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