Click here to Skip to main content
15,887,027 members
Home / Discussions / C#
   

C#

 
GeneralRe: You say filename I say file name. Or vice versa. Or neither. Pin
Kevin McFarlane27-Jan-12 1:35
Kevin McFarlane27-Jan-12 1:35 
AnswerRe: Naming Question Pin
Abhinav S26-Jan-12 20:23
Abhinav S26-Jan-12 20:23 
GeneralRe: Naming Question Pin
AmitGajjar26-Jan-12 22:26
professionalAmitGajjar26-Jan-12 22:26 
GeneralRe: Naming Question Pin
Subin Mavunkal27-Jan-12 0:27
Subin Mavunkal27-Jan-12 0:27 
GeneralRe: Naming Question Pin
Kevin McFarlane27-Jan-12 1:30
Kevin McFarlane27-Jan-12 1:30 
QuestionBitmap.Lockbytes AccessViolation Pin
Ylno25-Jan-12 4:24
Ylno25-Jan-12 4:24 
AnswerRe: Bitmap.Lockbytes AccessViolation Pin
Luc Pattyn25-Jan-12 6:17
sitebuilderLuc Pattyn25-Jan-12 6:17 
GeneralRe: Bitmap.Lockbytes AccessViolation Pin
Ylno25-Jan-12 11:22
Ylno25-Jan-12 11:22 
Hi Luc,

1) in this test 1000x1000 but in practice 1024x1024 or 2048x2048

2) using bmp.PixelFormat (see below)

3) the line with
row[i * PixelDepth] = pixVal;
within the inner loop throws.

background: I'm parsing grayscale pixel data from an obscure image format used in electron-microscopy. Along with the pixel values I get the Width, Height and PixelDepth. The actual image has been acquired on expensive ccd equipment therefore pixels can be quite deep. I want to be able to display an array of greyscale pixel values (double[,] pixelValues) within a picture box. For this I see no other way than creating a Bitmap/Image in memory and displaying this. It appears .NET does not support deep greyscale therefore I thought for the purposes of display only I could rescale the pixelArray from double[,] to byte[,] and assign each of the RGB channels for a given pixel to the byte value from the temporary byte[,] array.

Towards this end my code creates a byte-buffer vector in which I encode a Bitmap. First I write the header in which I define the pixelDepth to be 32. Previously I thought I could use ARGB 32bbp format and push the byte pixelValue in R, G and B a constant in the A channel. This worked:

C#
....... code to write the bitmap header here ........
for (int j = Height - 1; j >= 0; j--)
{
    for (int i = 0; i < Width; i++)
    {
        pixVal = (byte)(PixelScaleFactor * (_internalPixelArray[i, j] - PixelOffset));
        buffer.writeByte(pixVal);
        buffer.writeByte(pixVal);
        buffer.writeByte(pixVal);
        buffer.writeByte(0);        // the alpha channel.
    }
}


I then use the bitmap encoded byte[] buffer to create a memory stream from which I create an image by:
Image.FromStream(new System.IO.MemoryStream(imageData))


This works but takes 200ms to encode and display an image. To make things
quicker I thought I might be able to by encoding a buffer with a bitmap header as above and not assign the pixel values immediately but instead create a Bitmap using the memory stream method which results in an images with all pixels as zero. Then once I have the Bitmap object used Lockbits to set the pixels. I got to point and got an AccessViolation. I thought my buffer might not be long enough so I backed up a bit and started testing with the code I posted. i.e. create a simple bitmap using Bitmap(width, height) constructor and specify the pixelDepth with the Lockbits method. This way I thought I would be allocated a memory block of the correct size.

I simply want to display a greyscale array of pixel-values I don't care about the loss of precision since I keep the actual pixelArray separately for image-processing operations.

by the way your company looks interesting.
cheers
AnswerRe: Bitmap.Lockbytes AccessViolation Pin
Luc Pattyn25-Jan-12 12:39
sitebuilderLuc Pattyn25-Jan-12 12:39 
GeneralRe: Bitmap.Lockbytes AccessViolation Pin
Ylno25-Jan-12 18:21
Ylno25-Jan-12 18:21 
AnswerRe: Bitmap.Lockbytes AccessViolation Pin
Luc Pattyn25-Jan-12 23:04
sitebuilderLuc Pattyn25-Jan-12 23:04 
GeneralRe: Bitmap.Lockbytes AccessViolation Pin
Ylno26-Jan-12 7:05
Ylno26-Jan-12 7:05 
Questioncontrols Pin
theanil25-Jan-12 3:40
theanil25-Jan-12 3:40 
AnswerRe: controls Pin
Pete O'Hanlon25-Jan-12 3:45
mvePete O'Hanlon25-Jan-12 3:45 
GeneralRe: controls Pin
theanil25-Jan-12 3:50
theanil25-Jan-12 3:50 
GeneralRe: controls Pin
Pete O'Hanlon25-Jan-12 3:57
mvePete O'Hanlon25-Jan-12 3:57 
GeneralRe: controls Pin
theanil25-Jan-12 4:01
theanil25-Jan-12 4:01 
AnswerRe: controls Pin
BillWoodruff27-Jan-12 7:20
professionalBillWoodruff27-Jan-12 7:20 
Questioncreate an application which generate table of the entered number.. Pin
rajiv kumar (abbi)24-Jan-12 23:01
rajiv kumar (abbi)24-Jan-12 23:01 
AnswerRe: create an application which generate table of the entered number.. Pin
Pete O'Hanlon24-Jan-12 23:19
mvePete O'Hanlon24-Jan-12 23:19 
AnswerRe: create an application which generate table of the entered number.. Pin
OriginalGriff24-Jan-12 23:40
mveOriginalGriff24-Jan-12 23:40 
AnswerRe: create an application which generate table of the entered number.. Pin
phil.o25-Jan-12 0:20
professionalphil.o25-Jan-12 0:20 
AnswerRe: create an application which generate table of the entered number.. Pin
Luc Pattyn25-Jan-12 0:45
sitebuilderLuc Pattyn25-Jan-12 0:45 
GeneralRe: create an application which generate table of the entered number.. Pin
Wayne Gaylard25-Jan-12 1:01
professionalWayne Gaylard25-Jan-12 1:01 
AnswerRe: create an application which generate table of the entered number.. Pin
Abhinav S25-Jan-12 0:47
Abhinav S25-Jan-12 0:47 

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.