473,756 Members | 3,655 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PictureBox control memory and speed BIG problem

I’m writing a Windows application.
In the form I have a Panel and inside the panel I have a PictureBox control.
I’m loading the PictureBox control with BMP image that has the following
criteria:
14174 x 7874 Pixels (111.61MPixels) , 1 BitsPerPixel, 3200x3200 DPI, No
Compression.
The memory consumption for loading this image should be 13.31 MB (13,952,776
Bytes) (this is what IrfanView takes, http://www.irfanview.com/).

I’m loading the BMP file like that:
pictureBox1.Ima ge = Image.FromFile( "MyFileName.bmp ", true);
// - or -
//pictureBox1.Ima ge = Image.FromFile( "MyFileName.bmp ");
pictureBox1.Siz eMode = PictureBoxSizeM ode.StretchImag e;
pictureBox1.Wid th = pictureBox1.Ima ge.Width;
pictureBox1.Hei ght = pictureBox1.Ima ge.Height;

And this way, I get image scrolling for free (see
http://www.codeproject.com/cs/miscctrl/PictureBox.asp).

After I load the image, the memory usage of my application is about 50 MB
according to the Windows ‘Task Manager’.

The trouble is that every time I try to move any scroll bar, or showing the
image after hiding it (or part of it) with another window, it redraws itself
very very slowly and the memory usage jump up to 430 MB for a few seconds.

I’m running this application on a Pentium 4 processor 2.4GHz and 1.5 GB RAM.
Can anybody tell me why this is happening and how can I make it run much
much faster with no memory eating?
--------
Thanks
Sharon
Nov 17 '05 #1
5 5803
Hi Sharon,

When you load the image into memory, GDI+ is allocating the memory it needs
to store the image. Then, when you start to draw to the image, it creates
a new image buffer of the same size (hence the doubling of the memory).

There isn't much you could do here, unless you can break the image down
into smaller images and process those.

You can also try to post in microsoft.publi c.win32.program mer.gdi newsgroup.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 17 '05 #2
Hi Kevin,

I can leave with twice the memory for every redraw, but it’s eating 10 times
the amount of memory for every redraw (from less then 50 MB to 430 MB).

I suspect that for every redraw it convert the image from 1 bit per pixel to
1 byte per pixel, therefore multiplying the memory consumption at least by 8.
It this is what happening, it’s very bad. It means that the PicturePox
control can work only with very small images.

But what about larger images? Isn’t there a .NET control that I can use for
them?
--------
Thanks
Sharon
Nov 17 '05 #3

"Sharon" <Sh*****@newsgr oups.nospam> wrote in message
news:85******** *************** ***********@mic rosoft.com...
Hi Kevin,

I can leave with twice the memory for every redraw, but it’s eating 10
times
the amount of memory for every redraw (from less then 50 MB to 430 MB).

I suspect that for every redraw it convert the image from 1 bit per pixel
to
1 byte per pixel, therefore multiplying the memory consumption at least by
8.
It this is what happening, it’s very bad. It means that the PicturePox
control can work only with very small images.

But what about larger images? Isn’t there a .NET control that I can use
for
them?
--------
Thanks
Sharon

A redraw of a loaded image does not change the memory consumption.
As I told you before, when you call Image.FromFile( ), GDI+ loads the
Filedata into memory and builds an internal Image object from it (done by
GDI+ function - GdipImageForceV alidation()), that means that you need aprox.
twice the memory (depending the pix. format and type of the file).

If you don't want this to happen, you can load the image from a stream like
this:

fs = new FileStream(valu e, FileMode.Open, FileAccess.Read Write);
Image = Image.FromStrea m(fs, false, false); // set third arg. to false to
prevent GdipImageForceV alidation to be called.

This has the advantage that the internal buffer is not created and the
memory taken depends on the size of the portion actually drawn, but the
disadvantage is that it's terrible slow when redrawing (scrolling etc...),
because the drawing engine has to read the pixeldata from the underlying
stream and convert it to a bitmap each time the "view" changes.

Anyway, it looks like you are trying to use the PictureBox control for other
purposes than it was designed for, that is being a static container for
simple reasonable sized images (smaller than the form or containing
control). What you are trying is to do is use this control to display much
larger images and hope that you can scroll real fast when the control area
is smaller than the image size.
I don't think you will find a .NET control that fits this purpose, I doubt
that such control can even be built using GDI+.

Willy.


Nov 17 '05 #4
Hello again Willy,

Thanks for your help.

I changed my code to load the image from stream as you posted and indeed it
is working smoothly with image I mentioned.
But now, it takes much more then the twice the memory, it consumes 437 MB
(20 MB before loading the image, and 457 MB after loading the image).
As I mentioned before, the image is BMP 14174 x 7874 pixels (111.61
MPixels), 1 bits per pixel, 3200x3200 DPI, No Compression and the memory
consumption for loading this image should be 13.31 MB.

So I tested to se its limit I tried to load the same image but sized 15748 x
28348 pixels (should take 53.23 MB (55,810,960 Bytes)), but I get
successfully exception (strange one): System.Componen tModel.Win32Exc eption
{The operation completed successfully}
Thrown by the
System.Windows. Forms.DibGraphi csBufferManager .CreateCompatib leDIB(IntPtr hdc,
IntPtr hpal, Int32 ulWidth, Int32 ulHeight, IntPtr& ppvBits)

Do you know that one?

I guess that the control convert the image from 1 bit per pixel to 1 byte
per pixel, it’s the only explanation I can imagine for that amount of memory
consumption. Still it doesn’t explain the so large memory it takes.

Can you elaborate on that?

If I can not use the PictureBox control for this kind of images, how can I
do that in any other way?
---------
Thanks
Sharon
Nov 17 '05 #5
Hi Sharon,

In this case, you might need some third party components which have better
performance on large pictures. Or you have to write your own control to
display and scroll.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3349
by: CroDude | last post by:
Hi all! I've made a little app that creates thumbnails and if user clicks on it, it displays the original picture in the picturebox on a panel control. In a thumbnail mouse down event I'm using static method Image.FromFile(string path).Something like this: this.mainApp.pictureBox1.Image = Image.FromFile( imagePath ) Well ... the problem starts when loading a image 3200x2400x24bit which is
7
6045
by: kebalex | last post by:
Hi, I have an app (written in .NET 2.0) which updates a picturebox according to some user input (a slider control). when the user makes a change i loop through all of the pixels, do a calculation and update the picture. i currently use the GDI SetPixel method on each pixel of the Pictureboxes image. This is proving far to slow, about 1.5 seconds on average. This app needs to display the update as fast as possible. Has anyone got any...
4
2307
by: kimiraikkonen | last post by:
Hi, On my system which is 2.4GHZ P4 CPU, 1GB memory + 64MB DDR graphic card, if i create a simple picturebox docked on a form sized about 500x350 or less or more, doesn't matter, and also if i place a normal sized picture on the control, while dragging the form having with picturebox + image, it costs about %90-%100 CPU while dragging form around the screen. And screen is shown as very noticeably sluttering and distorted etc. Note that i...
3
5373
by: kirk | last post by:
I have a form with a PictureBox control on it. The .Image property is set to a PNG file(which shows the picture of the US map) with some transparency in it. The .BackColor property is set to Transparent. This so far, works perfect. I now, would like to put another PNG image(an arrow showing positioning on the map) over the last PictureBox. The problem i'm having, the background for this second PictureBox only stays transparent when...
0
9275
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10034
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9843
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9713
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8713
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6534
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5142
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3358
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2666
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.