keithcsl
asked on
Need Help on Imaging Problem...
I have a CCD camera sending data to my PC. I managed to aquire the data and put it into an array. The image is grayscale, thus the array is of type byte.
I need to display the image on the screen close to real time. This is my source code:
var imageBuffer: array[0..249,0..249] of byte;
arrayPtr: Pointer;
begin
arrayPtr:= addr(imageBuffer);
Image.Picture.Bitmap.Width := 250;
Image.Picture.Bitmap.Heigh t := 250;
MakePalette; // My grayscale palette
{ Fill up imageBuffer }
SetBitmapBits(Image.Pictur e.Bitmap.H andle, sizeof(imageBuffer),ArrayP tr);
Image.Refresh;
My problem is that the image is only half filled!! I read the help files and found that the SetBitmapBits takes in an array of words, not bytes. how do i solve this problem?
I have gone through all the previously asked questions and I have found 2 answers which partially help my problem.
This first one is entitled "Bitmap Palette" asked by tier and answered by javiertb (Question #294 date: 05/08). I have a very similar code to tier. How did tier manage to use the arary of bytes?
The second mail is entitled "Displaying bitmaps from memory" asked by Thales and answered by Sperling (Question #387 Date: 04/23). Should I incorporate this method to my solution?
I need some guidance. I am not sure how much this question is worth, but if you feel that it is too low, i'll be happy to increase it. :)
Kind regards
keith
I need to display the image on the screen close to real time. This is my source code:
var imageBuffer: array[0..249,0..249] of byte;
arrayPtr: Pointer;
begin
arrayPtr:= addr(imageBuffer);
Image.Picture.Bitmap.Width
Image.Picture.Bitmap.Heigh
MakePalette; // My grayscale palette
{ Fill up imageBuffer }
SetBitmapBits(Image.Pictur
Image.Refresh;
My problem is that the image is only half filled!! I read the help files and found that the SetBitmapBits takes in an array of words, not bytes. how do i solve this problem?
I have gone through all the previously asked questions and I have found 2 answers which partially help my problem.
This first one is entitled "Bitmap Palette" asked by tier and answered by javiertb (Question #294 date: 05/08). I have a very similar code to tier. How did tier manage to use the arary of bytes?
The second mail is entitled "Displaying bitmaps from memory" asked by Thales and answered by Sperling (Question #387 Date: 04/23). Should I incorporate this method to my solution?
I need some guidance. I am not sure how much this question is worth, but if you feel that it is too low, i'll be happy to increase it. :)
Kind regards
keith
This may be a stupid answer, so I let it go only as a comment.
Isn't it possible to actually convert those bytes to word's on
the fly?
If that works, well...
Good luck anyway.
(Maybe I just didn't understand your problem fully)
Morten Brendefur.
brendefu@online.no
Isn't it possible to actually convert those bytes to word's on
the fly?
If that works, well...
Good luck anyway.
(Maybe I just didn't understand your problem fully)
Morten Brendefur.
brendefu@online.no
Image can contain planes.
ASKER
i have tried using an array of type word. first of all, this change managed to fill the image. but when i tried filling the buffer with values 0 to 255, i did not get the gradient fill i expected. i got 8 strips of gradient fill instead of 1 single strip (top to bottom). i would expect this because 0 - 255 is $0000 - $00FF. i don't know how to map the byte to a word.
the second problem is my palette. i still cannot produce a grayscale image.
i would be most grateful if magic_wizard or mirek or anyone would like to see my source code.
the second problem is my palette. i still cannot produce a grayscale image.
i would be most grateful if magic_wizard or mirek or anyone would like to see my source code.
ASKER
This is my source code (i managed to reach this far with the help of my russian friend, anatoly):
var
Form1: TForm1;
hPal: HPalette;
implementation
{$R *.DFM}
procedure TForm1.MakePalette;
var
LogicalPalette: PLogPalette;
ColorIndex : LongInt;
begin
GetMem(LogicalPalette, (SizeOf(TLogPalette) + SizeOf(TPaletteEntry)*256) );
GetSystemPaletteEntries(Ca nvas.Handl e, 0, 256, LogicalPalette^.palPalEntr y[0]);
with LogicalPalette^ do
begin
palVersion := $300;
palNumEntries := 256;
{$R-}
for ColorIndex := 10 to 245 do
with palPalEntry[ColorIndex] do
begin
peRed := 255 - (ColorIndex-10);
peGreen := 255 - (ColorIndex-10);
peBlue := 255 - (ColorIndex-10);
peFlags := PC_NOCOLLAPSE;
end;
end;
{$R+}
DeleteObject(hPal); // Prevent Memory leakage by deleting old palette
hPal := CreatePalette(LogicalPalet te^);
FreeMem(LogicalPalette, (SizeOf(TLogPalette) + SizeOf(TPaletteEntry)*256) );
end;
procedure TForm1.Button2Click(Sender : TObject);
var
ImageBuffer : array[0..254,0..254] of word;
I,J,N : Integer;
ArrayPtr : Pointer;
begin
Image.Picture.Bitmap.Width := High(ImageBuffer)-1;
Image.Picture.Bitmap.Heigh t := High(ImageBuffer[1])-1;
ArrayPtr := @imageBuffer;
MakePalette;
SelectPalette(Image.Canvas .Handle,hP al,FALSE);
RealizePalette(Image.Canva s.Handle);
Image.Picture.Bitmap.Palet te := hPal;
for n:= 1 to 25 do begin
for i:= Low(ImageBuffer) to High(ImageBuffer) do begin
for j:= Low(ImageBuffer[1]) to High(ImageBuffer[1]) do begin
ImageBuffer[i,j]:= j;
end;
end;
SetBitmapBits(Image.Pictur e.Bitmap.H andle,Size Of(imageBu ffer),Arra yPtr);
Image.Refresh;
end;
end;
var
Form1: TForm1;
hPal: HPalette;
implementation
{$R *.DFM}
procedure TForm1.MakePalette;
var
LogicalPalette: PLogPalette;
ColorIndex : LongInt;
begin
GetMem(LogicalPalette, (SizeOf(TLogPalette) + SizeOf(TPaletteEntry)*256)
GetSystemPaletteEntries(Ca
with LogicalPalette^ do
begin
palVersion := $300;
palNumEntries := 256;
{$R-}
for ColorIndex := 10 to 245 do
with palPalEntry[ColorIndex] do
begin
peRed := 255 - (ColorIndex-10);
peGreen := 255 - (ColorIndex-10);
peBlue := 255 - (ColorIndex-10);
peFlags := PC_NOCOLLAPSE;
end;
end;
{$R+}
DeleteObject(hPal); // Prevent Memory leakage by deleting old palette
hPal := CreatePalette(LogicalPalet
FreeMem(LogicalPalette, (SizeOf(TLogPalette) + SizeOf(TPaletteEntry)*256)
end;
procedure TForm1.Button2Click(Sender
var
ImageBuffer : array[0..254,0..254] of word;
I,J,N : Integer;
ArrayPtr : Pointer;
begin
Image.Picture.Bitmap.Width
Image.Picture.Bitmap.Heigh
ArrayPtr := @imageBuffer;
MakePalette;
SelectPalette(Image.Canvas
RealizePalette(Image.Canva
Image.Picture.Bitmap.Palet
for n:= 1 to 25 do begin
for i:= Low(ImageBuffer) to High(ImageBuffer) do begin
for j:= Low(ImageBuffer[1]) to High(ImageBuffer[1]) do begin
ImageBuffer[i,j]:= j;
end;
end;
SetBitmapBits(Image.Pictur
Image.Refresh;
end;
end;
Sorry. You cant do this in this way.
Tell me what you'r program need show and i write code for you.
Tell me what you'r program need show and i write code for you.
ASKER
This is the specifications of my program:
poll the printer port for video data. i get the video 1 frame at a time and display the image on the screen. 1 frame is 250x250. this means my array is 62500 bytes long. the code is like this:
for i := 0 to rowSize do
for j := 0 to colSize do
imageBuffer[i,j] := GetDataFromPort(PortAddres s); // puts a byte into the array
then, all i need to do is to display this grayscale image on the screen.
if you need more information, please ask. lastly, i would like to thank you, mirek, in advance for helping me out.
poll the printer port for video data. i get the video 1 frame at a time and display the image on the screen. 1 frame is 250x250. this means my array is 62500 bytes long. the code is like this:
for i := 0 to rowSize do
for j := 0 to colSize do
imageBuffer[i,j] := GetDataFromPort(PortAddres
then, all i need to do is to display this grayscale image on the screen.
if you need more information, please ask. lastly, i would like to thank you, mirek, in advance for helping me out.
ASKER
This is the specifications of my program:
poll the printer port for video data. i get the video 1 frame at a time and display the image on the screen. 1 frame is 250x250. this means my array is 62500 bytes long. the code is like this:
for i := 0 to rowSize do
for j := 0 to colSize do
imageBuffer[i,j] := GetDataFromPort(PortAddres s); // puts a byte into the array
then, all i need to do is to display this grayscale image on the screen.
if you need more information, please ask. lastly, i would like to thank you, mirek, in advance for helping me out.
poll the printer port for video data. i get the video 1 frame at a time and display the image on the screen. 1 frame is 250x250. this means my array is 62500 bytes long. the code is like this:
for i := 0 to rowSize do
for j := 0 to colSize do
imageBuffer[i,j] := GetDataFromPort(PortAddres
then, all i need to do is to display this grayscale image on the screen.
if you need more information, please ask. lastly, i would like to thank you, mirek, in advance for helping me out.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Fantastic Results!!!
Thank you so much for your help, mirek. The code is excellent! I think this question is worth more than 100 points. Well, I have only 82 points left on me and I think you deserve it all.
Very Statisfied,
keith
Thank you so much for your help, mirek. The code is excellent! I think this question is worth more than 100 points. Well, I have only 82 points left on me and I think you deserve it all.
Very Statisfied,
keith
ASKER
Hei, how come the points did not get through to you? I will enquire on this...
I don't need more point's
ASKER