Bitmap Resolution setting help
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Bitmap Resolution setting help

  1. #1
    Join Date
    Jun 2010
    Posts
    6

    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
    Posts
    61

    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:

    Code:
    byte[] bytes = Encoding.UTF8.GetBytes("300/1");
    PropertyItem item = pic.GetPropertyItem(0x011a);//X-resolution tag defined in EXIF standard
    item.Value = bytes;
    pic.SetPropertyItem(item);
    item =  pic.GetPropertyItem(0x011b);//Y-resolution tag defined in EXIF standard
    item.Value = bytes;
    pic.SetPropertyItem(item);
    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

This is a CodeGuru survey question.


Featured


HTML5 Development Center