473,387 Members | 1,512 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Region requires much memory !?

Hi !!

To draw multiple graphics objects which have different shapes, I’m using
the region class to exclude/union the drawing area of these Objects.

The rectangle around a single object is of the size of 80x80 pixels. So
looping through these pixels and excluding the area of every transparent
pixel, the region will be built.

Afterwards, such an object has a memory usage of approx. 700Kb (before
modifying the region it was nearly 300kb).

So can anybody tell me, how to provide Objects with transparent
background and also keeping the memory usage low.

A weblink to more information about this region class would also be
helpful.

Thanks in advance,

Martin.
PS: Special thanks to Tom Overbay who provided me with the first code to
create user icons.

Here is a code snippet to show, what the program does:

For y = 0 To MyBitmap.Height - 1
For x = 0 To MyBitmap.Width - 1
' Exclude alpha pixels
If MyBitmap.GetPixel(x, y).A = 0 Then
MyRegion.Exclude(New Rectangle(x, y, 1, 1))
End If
Next
Next
..
..

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #1
5 1741
Hello,

"Martin Wolff" <ma***@111.com> schrieb:
The rectangle around a single object is of the size
of 80x80 pixels. So looping through these pixels and excluding
the area of every transparent pixel, the region will be built.

Afterwards, such an object has a memory usage of approx.
700Kb (before modifying the region it was nearly 300kb).
You are right -- "complex" regions need a lot of memory.
So can anybody tell me, how to provide Objects
with transparent background and also keeping the
memory usage low.


Sorry, I don't have a sample, but why not drawing everything onto one
control? You can safe parts of the image in separate buffers and restore
them when moving objects.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #2
Herfried,

thank you for your fast answer and your suggestion. But I think that
won't be the fine OOP way.
I prefer to have the objects doing their stuff themself. The handling
will be much easier when copying or deleting such a symbol, if they have
all the information close to them.

Will the memory usage go down, if I combine empty pixels to a bigger
rectangle before excluding them ?

Thanks in advance,

regards,
Martin.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #3
Martin,
In addition to Herfried's comments.

Would it be easier to define the 'shape' in terms of a GraphicsPath object?

Rather then checking bits on the bitmap, draw the shape onto the
GraphicsPath to begin with?

Or are you actually reading the bitmaps from files rather than creating
them?

According to Charles Petzold in "Programming Microsoft Windows with
Microsoft Visual Basic.NET"

"With the introduction of paths, regions have become much
less important in Windows graphics programming.
They might even be ignored altogether if not for the role
they play in clipping"

I normally start with a GraphicsPath then convert it into a Region, only
when I need it as a Region. For the clipping region for example.

Does the Clone method of the Region return a more compact Region?

Hope this helps
Jay
"Martin Wolff" <ma***@111.com> wrote in message
news:uX**************@TK2MSFTNGP09.phx.gbl...
Hi !!

To draw multiple graphics objects which have different shapes, I'm using
the region class to exclude/union the drawing area of these Objects.

The rectangle around a single object is of the size of 80x80 pixels. So
looping through these pixels and excluding the area of every transparent
pixel, the region will be built.

Afterwards, such an object has a memory usage of approx. 700Kb (before
modifying the region it was nearly 300kb).

So can anybody tell me, how to provide Objects with transparent
background and also keeping the memory usage low.

A weblink to more information about this region class would also be
helpful.

Thanks in advance,

Martin.
PS: Special thanks to Tom Overbay who provided me with the first code to
create user icons.

Here is a code snippet to show, what the program does:

For y = 0 To MyBitmap.Height - 1
For x = 0 To MyBitmap.Width - 1
' Exclude alpha pixels
If MyBitmap.GetPixel(x, y).A = 0 Then
MyRegion.Exclude(New Rectangle(x, y, 1, 1))
End If
Next
Next
.
.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 20 '05 #4
Hi Martin,

I'm confused by your numbers. An 80 x 80 x 4 (true colour) image is only
25600 bytes. How do you get to the 300K region, let alone 700K?? Was 80x80 a
type?

One thing is certain however, your current method is very costly per
pixel. It creates a 1x1 Rectangle (16 bytes) and adds that to a Region.
Assuming that the Region doesn't merge its rectangles, it needs to store its
Rectangles in some data structure. This would need memory allocation requiring
at least another 8 bytes, probably more. All this is per pixel!

Jay's idea of using a GraphicsPath would make it much more efficient
(assuming, of course, that much of these excluded pixels are contiguous).

If you are starting with a bitmap, there are a number of methods for
creating larger regions, and for creating completely enclosed areas, suitable
for representation using a GraphicsPath.

At the very least, rather than adding pixels to the region separately, you
could do horizontal scans and collect runs of pixels. A further step would be
to take a series of such runs (line 1, line 2, etc), and determine whether and
how they overlap vertically. These could then be converted to blocks plus bits
of runs, or, better, into a single GraphicsPath region.

Come back if you need more help on this. :-)

Regards,
Fergus
Nov 20 '05 #5

Thank you Jay and Fergus,

I will try to use GraphicsPath instead of the Region, if this will
provide me a transparency too.

Regards,

Martin.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #6

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

Similar topics

11
by: Altramagnus | last post by:
I have a complicated Region object, which I need to draw the outline, but not fill How can I convert the Region object to GraphicsPath object? or How can I draw the outline of the Region object?
3
by: dm1608 | last post by:
I have an Ecommerce application that uses mostly ASP and a bit of ASP.NET. Monitoring the servers memory via SNMP every 5 minutes would indicate that there is a memory leak somewhere within the...
0
by: Tim Marshall | last post by:
HI folks, I'm doing an app that requires the user to be able to choose a country, then a state/province/territory, then a city and possibly somewhere in-between, some kind of region, perhaps...
37
by: Ajai Jose | last post by:
Hi , I work on an ARM processor based embedded system. Code is mainly in C language. The project has a huge source base. We are supposed to optimise it. Most datastructures are declared as static...
232
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first...
3
by: Xiaoning He | last post by:
hi currently i'm using a crawler called larbin to get some pages, it hashes each url to an integer. This is not a good method comparing to md5, however it's enough for me. Currently i set the hash...
11
by: Chris Thomasson | last post by:
Here is the code: http://pastebin.com/m4a405e67 One advantage to using a region allocator is that you can usually skip most calls to free. Instead you can merge multiple free calls into a...
8
by: Chris M. Thomasson | last post by:
Here is the initial crude implmentation which compiles under Comeau with no warnings: ___________________________________________________________________ #include <cassert> #include <cstdlib>...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.