CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2010

    Bitmap Resolution setting help

    Dear All,

    I have an image 1200*900 using 300 dpi added as a resource in my project

    im using following code

    Bitmap pic = new Bitmap(Project1.Properties.Resources.Picture);

    Source image resolution is 300 dpi but when i create new Bitmap object it converts its resolution
    to 96 dpi. i want it to remain 300 dpi.

    i dont want to use setresolution (300f,300f) becuse it zooms in information in the source file

    any help

  2. #2
    Join Date
    Dec 2011

    Re: Bitmap Resolution setting help

    You don't need to use Bitmap pic = new Bitmap(Project1.Properties.Resources.Picture);

    Project1.Properties.Resources.Picture should be Image type. Say if you want to display it in a picturebox, simply write:

    picturebox1.Image = Project1.Properties.Resources.Picture;

    and the resolution will remain unchanged as 300dpi.

    If you just store the path of the image in your resource file, first use:

    Image pic = Image.FromFile(Project1.Properties.Resources.Picture);

    to load the image, then write something like this:

    byte[] bytes = Encoding.UTF8.GetBytes("300/1");
    PropertyItem item = pic.GetPropertyItem(0x011a);//X-resolution tag defined in EXIF standard
    item.Value = bytes;
    item =  pic.GetPropertyItem(0x011b);//Y-resolution tag defined in EXIF standard
    item.Value = bytes;
    If you use Bitmap to load the image, you may have to use SetResolution method to change the resolution.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.