[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Storing bitmaps in memory

Posted on 1998-01-01
11
Medium Priority
?
460 Views
Last Modified: 2010-04-04
My question concerns storing bitmaps in memory. I wish to
store bitmapped data in memory but I get a problem with
Windows' resources. I think it has something to do with
the device context connected to every bitmap I create. I
guess those device contexts are rather limited, so my
question is how can I store a data from bitmap in some
memory segment and then return it to bitmap form. I've
seen that there's a GetDIB function in the System unit,
but I haven't found something like SetDIB... Any
suggestions ( best with code implementations ) would be
appriciated, 10q.
0
Comment
Question by:nir_l
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +2
11 Comments
 
LVL 3

Expert Comment

by:Matvey
ID: 1355054
Well, what for do you need to store it this way?
Why not create a TBitmap object and load the BMP into it?

Matvey
0
 

Author Comment

by:nir_l
ID: 1355055
That's excatly what I currently do. The problem is ( as
presented ) that a TBitmap needs a device context which
is a windows resource. When you use 100s of TBitmaps your
resources run out EVEN if you have enough memory. I try
to use GetDIB to store only the bitmap data and not the
data and resources needed.
0
 
LVL 3

Expert Comment

by:Matvey
ID: 1355056
How many colors dos your BMP have? (2, 16, 256...)
And which version of Delphi do you use? Because it depands, I had the same problem...

Matvey
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:nir_l
ID: 1355057
I use Delphi 1.0 under W95. I also use DDBs ( that's what
TBitmap is ) and not DIBs, although I would rather use
the latter...
I have to store a few hundreds of bitmaps.
0
 
LVL 3

Expert Comment

by:Matvey
ID: 1355058
If you have enough resources you shell have no problems when the palete of your TBitmap is correct. My problem was:
When I used a 20MB- 16 colors BMP, I also ran out of resources because the palete was set to 256 colors.

So try limiting the palete (I think you can do it by loading some BMP with a defined range of colors (examples from Delphi in the images/splash/16color or smth like that, before you DRAW yours on it).
If I'll find it, I'll send you the code, not right now...

So try doing smth like that, good luck to you and a happy new year!
Matvey
0
 
LVL 1

Expert Comment

by:bcrotaz
ID: 1355059
Try creating one bitmap, and putting all your bitmaps in it, using Canvas.Draw(0,y,MyBmp), and make 'y' the current height of the stored bmp.  Then just increase the height of the bmp just before you add a bmp.
Put it together into a component, and it should be reasonably simple.  Just keep a list of the y positions and heights of each bmp.  If the widths are variable, make the stored bmp width large enough to hold the largest currently stored bmp.  Height and width can be dynamic.

Good Luck.

bryan  
0
 

Author Comment

by:nir_l
ID: 1355060
Matvey - I have enough system resources so the fact
the bitmaps are true-color doesn't realy hurt me.
However, they do waste much more space in memory so
I'd rather save them in memory in their default
color and convert them to true color only when needed.
I didn't find any sources of doing that, however.

Bcrotaz - I've got the small bitmaps suggestions tons
of times and they won't do because my bitmaps vary
in size. Using this way would be very clumsy and
resource consuming.


Thanks for the suggestions.
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1355061
Hi nir_l,

maybe, setdib is not the correct word, what about createdib?

Look for an example?

www.delphideli.com/download/dibdemo.zip

Hope this is what you were looking for.

Have fun,
c.u. ZifNab;


0
 
LVL 1

Accepted Solution

by:
rchambel earned 400 total points
ID: 1355062
You have a few functions to create a memory handle like good old pascal's GetMem().

GlobalAlloc(): Create a memory handle.
GlobalLock(): Lock the memory (windows can move memory to fill in the memory holes left my other memory allocations) and obtain a pointer.
GlobalUnlock(): to release that pointer and enable Windows to take control of that piece of memory.
GlobalFree(): Release the memory handle.

And they're used in that order.

After you create the memory handle, DO NOT destroy or change it! that handle is a pointer to Windows Global memory and Windows itself is responsible for it's maintainance.

When you GlobalLock(theHandle) you get a pointer to that memory.
You can do CopyMemory() from the Bitmap's handle to the new handle.
After that, you may GlobalUnlock(thePointer) and whenever you need that pointer again you re-lock it - remember it's a new pointer since Windows might have changed its position.

After you've finished using that memory, GlobalFree(theHandle).

Tomorrow, I'll post you a comment using this functions.

NOW, for the easy part: Use AllocMem (it GlobalAlloc()s  and GlobalLock()s all at the same time) and FreeMem() to free it!
0
 

Author Comment

by:nir_l
ID: 1355063
The demo shows also how to show images. And it's an example of creating dib's, I guess they also show how you can put these on to screen.  
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1355064
Sorry, haven't seen your commet before, I shall
check this address now... 10q.
0

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question