Click here to Skip to main content
16,007,163 members
Home / Discussions / C#
   

C#

 
AnswerRe: Casting from derived class to base class Pin
Ret Orrick6-Jun-06 15:49
Ret Orrick6-Jun-06 15:49 
QuestionPlease Help ! Pin
mostafa_h6-Jun-06 4:25
mostafa_h6-Jun-06 4:25 
AnswerRe: Please Help ! Pin
CodyGen6-Jun-06 5:45
CodyGen6-Jun-06 5:45 
GeneralRe: Please Help ! Pin
mostafa_h6-Jun-06 11:25
mostafa_h6-Jun-06 11:25 
Questionquestion about time and date format ? [modified] Pin
cmpeng346-Jun-06 4:20
cmpeng346-Jun-06 4:20 
AnswerRe: question about time and date format ? Pin
Dustin Metzgar6-Jun-06 4:39
Dustin Metzgar6-Jun-06 4:39 
AnswerRe: question about time and date format ? [modified] Pin
Wjousts6-Jun-06 4:40
Wjousts6-Jun-06 4:40 
QuestionDirect instantiation of Bitmap from unsafe memory Pin
Florian Storck6-Jun-06 4:10
Florian Storck6-Jun-06 4:10 
Hi there,

I'm quite exhausted now trying to directly set the Scan0 Paramater of a Bitmap to avoid slow copying bitmaps in memory.
Basically, I try to do the following:

1.) I have a buffer containing already loaded Bitmap files in memory. Fo r performance reasons, this buffer is allocated via VirtualAlloc and therefore unsafe.

2.) I'm passing a UnmanagedMemoryStream with a subportion of the buffer to my Drawing function, pointing to the beginning of the bitmap file.

3.) I'll try to instantiate a bitmap, using the Streampointer to use the buffer directly and draw it to the screen ( or better, a backbuffer).

This looks like this:

<br />
<br />
 // linear buffer containing bmp file<br />
unsafe<br />
{<br />
  UnmanagedMemoryStream mstr= new     UnmanagedMemoryStream((byte*)buf.ptrStart.ToPointer(),   buf.Count, buf.Count, FileAccess.Read);<br />
}<br />
 BitmapData bmd;<br />
<br />
 BufferBitmap = new Bitmap(1920, 1080);<br />
 <br />
 ImageLockMode fLock = ImageLockMode.UserInputBuffer;<br />
<br />
// causes "Invalid Parameter" exception at the moment<br />
  bmd = BufferBitmap.LockBits(new Rectangle(0,0,1920,1080),<br />
                                fLock,PixelFormat.Format24bppRgb);<br />
 unsafe<br />
 {<br />
   bmd.Scan0 = new IntPtr(mstr.PositionPointer+14);<br />
 }<br />
<br />
 BufferBitmap.Unlock(bmd); <br />
<br />
 GfxBuffer.Graphics.DrawImageUnscaled(BufferBitmap, new Point(0,0));<br />
<br />


Well, all I get is a "Invalid Parameter" Exception when setting the LockBits with the UserInputBuffer Flag, or, if I use the ReadWrite Flag, I would probably have to use the buffer the Bitmapobject manages, which would be an unnecessary copy operation. I just want to display the bitmap I've already in memory which the smallest possible effort.

Does anybody have an idea whats going wrong here ? According to some examples I found, it should work this way. Interestingly, even if a try to pass a buffer allocated with Marshal.AllocHGlobal the LockBits operation fails...

The buffer contains valid data, because this code works, but I think, this causes every time an instantiation and copy procedure:

<br />
                    // GfxBuffer.Graphics.DrawImageUnscaled(Bitmap.FromStream(mstr,false), new Point(0,0));<br />
<br />


Bye,
Florian
QuestionGet file that spawned the application. Pin
cmarcus6-Jun-06 4:01
cmarcus6-Jun-06 4:01 
AnswerRe: Get file that spawned the application. Pin
Stephan Samuel6-Jun-06 4:08
Stephan Samuel6-Jun-06 4:08 
GeneralRe: Get file that spawned the application. Pin
cmarcus6-Jun-06 5:58
cmarcus6-Jun-06 5:58 
AnswerRe: Get file that spawned the application. Pin
J4amieC6-Jun-06 4:11
J4amieC6-Jun-06 4:11 
AnswerRe: Get file that spawned the application - New Problem Pin
cmarcus6-Jun-06 8:44
cmarcus6-Jun-06 8:44 
QuestionShared Add-in for Excel 2003 and Garbage Collector Pin
Kadur6-Jun-06 3:55
Kadur6-Jun-06 3:55 
QuestionObject lifetime, GC and the State Pattern [modified] Pin
User 66586-Jun-06 3:54
User 66586-Jun-06 3:54 
AnswerRe: Object lifetime, GC and the State Pattern [modified] Pin
Stephan Samuel6-Jun-06 4:03
Stephan Samuel6-Jun-06 4:03 
GeneralRe: Object lifetime, GC and the State Pattern [modified] Pin
User 66586-Jun-06 4:07
User 66586-Jun-06 4:07 
GeneralRe: Object lifetime, GC and the State Pattern Pin
Stephan Samuel6-Jun-06 6:53
Stephan Samuel6-Jun-06 6:53 
GeneralRe: Object lifetime, GC and the State Pattern Pin
User 66586-Jun-06 7:51
User 66586-Jun-06 7:51 
AnswerRe: Object lifetime, GC and the State Pattern [modified] Pin
Guffa6-Jun-06 4:23
Guffa6-Jun-06 4:23 
GeneralRe: Object lifetime, GC and the State Pattern [modified] Pin
User 66586-Jun-06 4:28
User 66586-Jun-06 4:28 
AnswerRe: Object lifetime, GC and the State Pattern [modified] Pin
Guffa6-Jun-06 8:50
Guffa6-Jun-06 8:50 
QuestionString manipulation performance issue Pin
sjembek6-Jun-06 3:37
sjembek6-Jun-06 3:37 
AnswerRe: String manipulation performance issue [modified] Pin
sathish s6-Jun-06 3:48
sathish s6-Jun-06 3:48 
GeneralRe: String manipulation performance issue [modified] Pin
sjembek6-Jun-06 4:04
sjembek6-Jun-06 4:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.