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

C#

 
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 
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 
Thanks again for getting back to me on this subject.


Luc Pattyn wrote:
I don't see it!

sorry, I simply meant my discussion about having pixels stored in a double[,] array but not really caring with what pixel-depth the bitmap is since is it is only for display purposes not calculation.

5. I guess "see above"

6. Same here. Other than GDI+ not fully supporting 16bpp. There is very little on the net regarding using 16bpp greyscale Bitmaps and what there is is old and contradictory.

7. I went with your suggestion here however I couldn't get things to work using PixelFormat.Format16bppGrayScale. Instead I went with 24bppRGB instead. For the benefit of others see code below.

8. yes, I was aware of this (once) but could you remind me of the benefits? My reasons for using 2D are:
8.1 - the dimensions are carried with the data in array.GetLength(int dimension). The vector approach requires lacks this.
8.2 - the array is analogous to the raster image and therefore conceptually simpler.
8.3 - this is my first 'real' stab at writing an heavy image processing application.

Aren't the 2D and 1D arrays arranged the same in memory?

Thanks again for your help. Pushed me towards a solution. Smile | :)

and finally here's what I came up with:

//  DEFINE AN IMAGE ALONG WITH ITS DIMENSIONS
// 24bpp -> three channels each of one byte depth
int width = 1000;
int height = 1000;
byte[] pixelVector = new byte[width * height * 3];
// FILL THE PIXELS WITH SOMEDATA AVOIDING OVERFLOW
for (int loop = 0; loop < (width * height ); loop+=3)
{
    pixelVector[loop]       = (byte)((loop * 256) / (width * height ));
    pixelVector[loop + 1]   = (byte)((loop * 256) / (width * height ));
    pixelVector[loop + 2]   = (byte)((loop * 256) / (width * height ));
}

// CREATE THE DESTINATION BITMAP WITH THE REQUIRED PIXEL-DEPTH
Bitmap bmp = new Bitmap(width, height, PixelFormat.Format24bppRgb);
// LOCK IT'S DATA FOR EXCLUSIVE ACCESS
BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, bmp.PixelFormat);
unsafe
{
    // GET THE ADDRESS OF THE FIRST PIXEL IN MEMORY
    byte* row = (byte*)bmpData.Scan0;
    // LOOP THROUGH THE PIXEL-DATA FILLING ONE PIXEL PER
    // ITERATION (THREE PIXELS PER CHANNEL)
    for (int loop = 0; loop < (pixelVector.Length*3); loop+=3){
        row[loop]   =   pixelVector[loop/3];        //
        row[loop + 1] = pixelVector[loop/3 ];
        row[loop + 2] = pixelVector[loop/3 ];
    }
}
bmp.UnlockBits(bmpData);

pictureBox1.Image = bmp;


modified 26-Jan-12 12:41pm.

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 
AnswerRe: create an application which generate table of the entered number.. Pin
PIEBALDconsult25-Jan-12 2:28
mvePIEBALDconsult25-Jan-12 2:28 
GeneralRe: create an application which generate table of the entered number.. Pin
Richard Andrew x6425-Jan-12 3:10
professionalRichard Andrew x6425-Jan-12 3:10 

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.