-
December 20th, 2011, 05:54 AM
#1
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
-
December 20th, 2011, 11:47 AM
#2
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|