473,396 Members | 2,154 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,396 software developers and data experts.

Boxing/Deboxing Bitmaps Problem

I am using Microsoft Visual Basic .net 2002 Standard. I am coding an application which loads in data from a compressed file. One of the items in the file is a raw RGB565 bitmap, at 800x600 pixels. In a previous version of my app, I used Bitmap.SetPixel() but performance got to be an issue as it took in some cases nearly 30 additional seconds to load the file. I am trying to use Bitmap.LockBits() in combination with Marshall.PtrToStruct() to map a two-dimensional array of Short over the actual bits in the bitmap. Unfortunately, Marshall.PtrToStruct() requires a well-formatted structure, and an array of anything is not acceptable. Thus, I attempted to create a class with 480,000 Short variables and a Property to access them in a manner similar to that I'd use if I were using an array. However, when I tried to load it in the IDE, my swap file broke through 2GB and went on climbing, from 200MB. Attempts to compile the 40MB source code beast by hand have been thwarted by a stack overflow in VBC, and I can't seem to find any option to increase VBC's stack size.

So, how do I manually get access to the bits in a bitmap, given the above troubles?
Nov 20 '05 #1
4 1291
The GDI+ FAQ has information on using LockBits.

I would suggest an iterative approach to mapping your data to the pixels in
the bitmap. Marshal.PtrTStructure will not be able to cope with the gaps in
the bitmap buffer that represent the stride padding in the BitmapData oject.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Image transition effects, snap-to-grid and Layered Windows are
all discussed in May's edition of Well Formed for C# or VB programmers
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://bobpowelldotnet.blogspot.com/atom.xml


"Andrew Cook" <Andrew Co**@discussions.microsoft.com> wrote in message
news:9E**********************************@microsof t.com...
I am using Microsoft Visual Basic .net 2002 Standard. I am coding an application which loads in data from a compressed file. One of the items in
the file is a raw RGB565 bitmap, at 800x600 pixels. In a previous version of
my app, I used Bitmap.SetPixel() but performance got to be an issue as it
took in some cases nearly 30 additional seconds to load the file. I am
trying to use Bitmap.LockBits() in combination with Marshall.PtrToStruct()
to map a two-dimensional array of Short over the actual bits in the bitmap.
Unfortunately, Marshall.PtrToStruct() requires a well-formatted structure,
and an array of anything is not acceptable. Thus, I attempted to create a
class with 480,000 Short variables and a Property to access them in a manner
similar to that I'd use if I were using an array. However, when I tried to
load it in the IDE, my swap file broke through 2GB and went on climbing,
from 200MB. Attempts to compile the 40MB source code beast by hand have been
thwarted by a stack overflow in VBC, and I can't seem to find any option to
increase VBC's stack size.
So, how do I manually get access to the bits in a bitmap, given the above

troubles?
Nov 20 '05 #2
Thanks, Mr. Powell, the iterative approach works fine, as far as I can tell, and the load time for the files has gone down exponentially. A perfect solution which does you much well-deserved credit.

But now I have another bitmap-related problem.

After getting all the information from the input file, my program renders all the information to a bitmap, which is then displayed on the screen in a PictureBox control. However, when I try to create a Graphics obeject for the Bitmap, I get an OutOfMemoryException originating in system.drawing.dll, in the exact same place as I got it in the previous version of my program. I don't quite understand why; even though I'm holding on to two other very large bitmaps and several other amounts of data at the time, I've got over a gig free in my paging file with room to expand, and it fails there on other, more advanced machines as well. GC.GetTotalMemory reports 1196440, or about 1.14 megabytes, but it isn't dealing with native heap. Task Manager reports 29,778KB in use. Having no experience in unmanaged programming has left me clueless as to where to go next.

"Bob Powell [MVP]" wrote:
The GDI+ FAQ has information on using LockBits.

I would suggest an iterative approach to mapping your data to the pixels in
the bitmap. Marshal.PtrTStructure will not be able to cope with the gaps in
the bitmap buffer that represent the stride padding in the BitmapData oject.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Nov 20 '05 #3
Does the bitmap use a colour palette? You can't get a graphics for a bitmap
with a palette.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Image transition effects, snap-to-grid and Layered Windows are
all discussed in May's edition of Well Formed for C# or VB programmers
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://bobpowelldotnet.blogspot.com/atom.xml


"Andrew Cook" <An********@discussions.microsoft.com> wrote in message
news:2C**********************************@microsof t.com...
Thanks, Mr. Powell, the iterative approach works fine, as far as I can tell, and the load time for the files has gone down exponentially. A perfect
solution which does you much well-deserved credit.
But now I have another bitmap-related problem.

After getting all the information from the input file, my program renders all the information to a bitmap, which is then displayed on the screen in a
PictureBox control. However, when I try to create a Graphics obeject for the
Bitmap, I get an OutOfMemoryException originating in system.drawing.dll, in
the exact same place as I got it in the previous version of my program. I
don't quite understand why; even though I'm holding on to two other very
large bitmaps and several other amounts of data at the time, I've got over a
gig free in my paging file with room to expand, and it fails there on other,
more advanced machines as well. GC.GetTotalMemory reports 1196440, or about
1.14 megabytes, but it isn't dealing with native heap. Task Manager reports
29,778KB in use. Having no experience in unmanaged programming has left me
clueless as to where to go next.
"Bob Powell [MVP]" wrote:
The GDI+ FAQ has information on using LockBits.

I would suggest an iterative approach to mapping your data to the pixels in the bitmap. Marshal.PtrTStructure will not be able to cope with the gaps in the bitmap buffer that represent the stride padding in the BitmapData oject.
--
Bob Powell [MVP]
Visual C#, System.Drawing

Nov 20 '05 #4
I beleive that you can only obtain a Graphics object for 32 or 24 bit
images. I will verify this and get back in this thread.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Image transition effects, snap-to-grid and Layered Windows are
all discussed in May's edition of Well Formed for C# or VB programmers
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://bobpowelldotnet.blogspot.com/atom.xml


"Andrew Cook" <An********@discussions.microsoft.com> wrote in message
news:14**********************************@microsof t.com...
No, it doesn't use a colour palette. It's PixelFormat.Format16bppRgb565. I get a different exception when I try to use a paletted bitmap.
"Bob Powell [MVP]" wrote:
Does the bitmap use a colour palette? You can't get a graphics for a bitmap with a palette.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Image transition effects, snap-to-grid and Layered Windows are
all discussed in May's edition of Well Formed for C# or VB programmers
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml Bob's Blog: http://bobpowelldotnet.blogspot.com/atom.xml

Nov 20 '05 #5

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

Similar topics

4
by: Michael Kennedy [UB] | last post by:
Hi Everyone, I have this multithreaded C# windows forms application which does a lot of image processing. Occasionally, I get the following error: A generic error occurred in GDI+....
43
by: Mountain Bikn' Guy | last post by:
I have a situation where an app writes data of various types (primitives and objects) into a single dimensional array of objects. (This array eventually becomes a row in a data table, but that's...
24
by: ALI-R | last post by:
Hi All, First of all I think this is gonna be one of those threads :-) since I have bunch of questions which make this very controversial:-0) Ok,Let's see: I was reading an article that When...
1
by: Mark Evans | last post by:
I have a dialog box and on it I want to display a bitmap, which will change at various times during the program. My problem is that the bitmaps will not be the same each time. I want the user to...
4
by: Peter Olcott | last post by:
I want to be able to make my .NET applications run just as fast as unmanaged C++. From my currently somewhat limited understanding of the .NET framework and the C# language, it seems that...
2
by: Mike | last post by:
Hello everybody. I am drawing a country map that consists of 149 municipality bitmaps, each around 25 Kb. I draw it onto the in-memory bitmap, then draw it on the picture box. I use C++, but...
94
by: Peter Olcott | last post by:
How can I create an ArrayList in the older version of .NET that does not require the expensive Boxing and UnBoxing operations? In my case it will be an ArrayList of structures of ordinal types. ...
19
by: ahjiang | last post by:
hi there,, what is the real advantage of boxing and unboxing operations in csharp? tried looking ard the internet but couldnt find any articles on it. appreciate any help
161
by: Peter Olcott | last post by:
According to Troelsen in "C# and the .NET Platform" "Boxing can be formally defined as the process of explicitly converting a value type into a corresponding reference type." I think that my...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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...
0
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...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.