Board index » cppbuilder » Drawing on bitmap
tm
![]() CBuilder Developer |
tm
![]() CBuilder Developer |
Drawing on bitmap2004-05-01 03:22:26 PM cppbuilder3 It's required to draw pixels on TBitmap. I've put TImage component on the Form, created Picture: Image->Picture = new TPicture(); But after the operation Image->Picture->Bitmap->Canvas->Pixels[x][y] = clRed; form remains empty. I know that I do this operation simply using Image->Canvas->Pixels[x][y] = clRed; Why? And how to do it correctly? Thank you in advance. |
Hans Galema
![]() CBuilder Developer |
2004-05-01 05:07:16 PM
Re:Drawing on bitmap
XXXX@XXXXX.COM wrote:
QuoteIt's required to draw pixels on TBitmap. |
Michael Kutscher
![]() CBuilder Developer |
2004-05-01 05:11:39 PM
Re:Drawing on bitmap
Hi,
QuoteImage->Picture = new TPicture(); memory-leaks. But it is neccessary, to set the bitmaps width and hight. Those are zero in a new bitmap - So You are drawing far beyond the borders of the bitmap. Image1->Picture->Bitmap->Width=whateveryouneed; Image1->Picture->Bitmap->Height=whateveryouneed; and it is also a good idea, to set the pixelformat according to Your needs - Otherwise, the results may depend on the actual settings of the computer: Image1->Picture->Bitmap->PixelFormat=pf24Bit; After this QuoteImage->Picture->Bitmap->Canvas->Pixels[x][y] = clRed; pixel on the screen. If You want to change a lot of pixels have a look at Bitmap->RowScan Good Luck Michael Kutscher www.kutscher-software.de {smallsort} |
tm
![]() CBuilder Developer |
2004-05-01 07:39:41 PM
Re:Drawing on bitmap
OK, it works now, thank you very much.
QuoteBy the way: Canvas->Pixels seems to be the slowest possible way to set a (also with pf32bit). So, the previous code was as follows: Graphics::TBitmap *Bitmap2; Bitmap2 = new Graphics::TBitmap(); Bitmap2->PixelFormat = pf24bit; Byte* ptr1, ptr2; for (int y = 0; y < pBitmap1->Height; y++) { ptr2 = (Byte *)pBitmap2->ScanLine[y]; ptr1 = (Byte *)pBitmap1->ScanLine[y]; memcpy(ptr1, ptr2, pBitmap1->Width*4); } At the first string in cycle ptr2 = (Byte *)pBitmap2->ScanLine[y]; at y = 0 the following error appears: EInvalidGraphicOperation with message 'Scan line index out of range'. Where is the problem here? Probably, there is another way to copy one bitmap to another? And how to modify this code if I want copy bits of pf32bit bitmap into pf24bit bitmap? Thanks in advance, TM |
Michael Kutscher
![]() CBuilder Developer |
2004-05-01 09:44:36 PM
Re:Drawing on bitmap
Hi,
QuoteGraphics::TBitmap *Bitmap2; QuoteByte* ptr1, ptr2; But, if You just want to copy pieces of a bitmap or a whole one, it might be the better way, to simply draw or CopyRect it on the other one. Thats less code and works fast as well. QuoteAnd how to modify this code if I want copy bits of pf32bit bitmap into Bitmap32->Canvas->Draw(0,0,Bitmap2); I don't know, wether Convas->CopyRect would work correctly in this situation, but I think it's worth a try. Modifying each pixel "manually" doesn't look very effective... Good luck Michael Kutscher |
tm
![]() CBuilder Developer |
2004-05-02 03:40:23 PM
Re:Drawing on bitmap
Thank you very much for your help and explanations.
QuoteI don't know, wether Convas->CopyRect would work correctly in this |