Load image problem
-
Hello, I want to load an JPEG image from file to a picturebox. I know that i can load using :
Picturebox1.image = image.fromfile("D:\MyImage.jpg")
and
dim b as new bitmap("D:\MyImage.jpg")
Picturebox1.image = bbut when I loading image using these ways, it loads bitmap format and uses more RAM space. (e.g a 3MB JPEG file uses 40MB RAM after loading) How Can I load the file with low RAM usage? UPDATE : Microsoft Paint also use 40MB RAM After open that file, but Microsoft Photo viewer use very low RAM usage. How can I load images with low RAM usage????? :confused::confused::confused::confused::confused::confused::confused::confused::confused::confused::confused:
Regards. Mehdi Ghiasi
-
Hello, I want to load an JPEG image from file to a picturebox. I know that i can load using :
Picturebox1.image = image.fromfile("D:\MyImage.jpg")
and
dim b as new bitmap("D:\MyImage.jpg")
Picturebox1.image = bbut when I loading image using these ways, it loads bitmap format and uses more RAM space. (e.g a 3MB JPEG file uses 40MB RAM after loading) How Can I load the file with low RAM usage? UPDATE : Microsoft Paint also use 40MB RAM After open that file, but Microsoft Photo viewer use very low RAM usage. How can I load images with low RAM usage????? :confused::confused::confused::confused::confused::confused::confused::confused::confused::confused::confused:
Regards. Mehdi Ghiasi
You can't. THe image is represented in memory as a 32-bit full resolution bitmap in memory. In the file, it's compressed down to whatever the JPEG encoding settings are. For example, an image that is 3000x2000 pixels will take up 24MB of memory at full resolution. The resulting image on screen will not be that large, so it'll get painted scaled down to whatever size is visible. There is no class in the .NET Framework that will reduce the memory size by representing the image in its file format. You'd have to either write your own class to do this or find a 3rd party library that does this. I don't know of any.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
Hello, I want to load an JPEG image from file to a picturebox. I know that i can load using :
Picturebox1.image = image.fromfile("D:\MyImage.jpg")
and
dim b as new bitmap("D:\MyImage.jpg")
Picturebox1.image = bbut when I loading image using these ways, it loads bitmap format and uses more RAM space. (e.g a 3MB JPEG file uses 40MB RAM after loading) How Can I load the file with low RAM usage? UPDATE : Microsoft Paint also use 40MB RAM After open that file, but Microsoft Photo viewer use very low RAM usage. How can I load images with low RAM usage????? :confused::confused::confused::confused::confused::confused::confused::confused::confused::confused::confused:
Regards. Mehdi Ghiasi
if, I repeat: if, your PictureBox is significantly smaller than the original image, then you could solve your problem by creating a new and smaller image, like so:
Bitmap bm1=Bitmap.FromFile(filespec);
Bitmap bm2=new Bitmap(bm1, myPictureBox.Size);
bm1.Dispose();
myPictureBox.Image=bm2;if not, there's nothing much you can do about it, as .NET keeps images in RAM as real bitmaps (normally 4B/px). :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
if, I repeat: if, your PictureBox is significantly smaller than the original image, then you could solve your problem by creating a new and smaller image, like so:
Bitmap bm1=Bitmap.FromFile(filespec);
Bitmap bm2=new Bitmap(bm1, myPictureBox.Size);
bm1.Dispose();
myPictureBox.Image=bm2;if not, there's nothing much you can do about it, as .NET keeps images in RAM as real bitmaps (normally 4B/px). :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
So, How Microsoft Photo viewer uses a little memory using full loading picture ? (it can zoom into picture with full quality) :confused::confused::confused::confused::confused::confused::confused::confused::confused::confused::confused: also delphi can load images as jpeg! Thanks for your answer.
Regards. Mehdi Ghiasi
modified on Friday, September 3, 2010 9:29 PM
-
So, How Microsoft Photo viewer uses a little memory using full loading picture ? (it can zoom into picture with full quality) :confused::confused::confused::confused::confused::confused::confused::confused::confused::confused::confused: also delphi can load images as jpeg! Thanks for your answer.
Regards. Mehdi Ghiasi
modified on Friday, September 3, 2010 9:29 PM
Probably because it implemented a custom class to represent the image in its native file format in memory. That would also mean it has to have custom rendering code to parse the image data, as needed, and only the sections of it that are required to render the visible part of the image on screen.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak