Board index » delphi » Create Bitmap and PutPixel anywhere in the bitmap

Create Bitmap and PutPixel anywhere in the bitmap

im using Delphi 4
i wanna create new 100x100 Pixel 256 color bitmap file
how can i create?

and then   i wanna put pixel  in the bitmap file

like this ...
 mybitmap:=create.bitmap[256 color,100,100 pixel]
  r:=255;
  g:=0
  b:=0;
  mybitmap.putpixel[50,50,r,g,b];
end;

Please help i really need that ...
thanks for your interests

 

Re:Create Bitmap and PutPixel anywhere in the bitmap


Quote
"RomanticCoder" <meh...@ossite.com> wrote in message

news:88ue2q$53l5@bornews.borland.com...

Quote
> im using Delphi 4
> i wanna create new 100x100 Pixel 256 color bitmap file
> how can i create?

> and then   i wanna put pixel  in the bitmap file

Using the Pixels property will be very slow.  Scanline will be much faster.
Look at the pf8bit section of:
http://www.efg2.com/Lab/ImageProcessing/Scanline.htm

Be aware that since you're working with 256-color bitmaps, you also need to
be concerned with getting the palette defined.  (Working with pf24bit is
much simpler since no palette need be defined.)

--
efg

Earl F. Glynn     E-Mail:  EarlGl...@att.net
Overland Park, KS  USA

efg's Computer Lab:  http://www.efg2.com/Lab

Re:Create Bitmap and PutPixel anywhere in the bitmap


Hi

Do you want to create a single bitmap or a bitmap in a TImage component ?

Now, i explain to create a single bitmap :

var
  MyBitmap : TBitmap;
begin
  MyBitmap:=TBitmap.Create;
  try
    MyBitmap.Width:=100;
    MyBitmap.Height:=100;

    MyBitmap.Canvas.PutPixel:=$....  // the color of the point;

    // after you do what you want
  finally
    MyBitmap.Dormant;  // to free the gdi resources
    MyBitmap.FreeImage;
    MyBitmap.ReleaseHandle;
    MyBitmap.Free;
  end;
end;

To define the color, you can use

RGB(red value, green value, blue value) : the values are in [0..255] (byte)
the result is a DWORD

Have a good development.

Cya. Philippe (FRANCE)

If you need others explains, ask me.

Re:Create Bitmap and PutPixel anywhere in the bitmap


You already asked nearly the same question. I don't know yet exactly
what's your real problem but let's try it once again:

function CreateBitmapWithColoredPixel(const r, g, b: Byte; const x, y: Integer):
TBitmap;
begin
  Result:= TBitmap.Create;
  try
    Result.Height := 100;
    Result.Width := 100;
    Result.PixelFormat := pf8bit;

    Result.Canvas.Pixels[x, y] := RGB(r, g, b);
  except
    Result := nil;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  MyBitmap: TBitmap;
begin
  MyBitmap := nil;
  MyBitmap := CreateBitmapWithColoredPixel(255, 0, 0, 50, 50);
  if MyBitmap <> nil then
    Canvas.Draw(10, 10, MyBitmap);
end;

To get a better solution it's necessary to know a little more what you
really want to achieve.

Regards
Toni

RomanticCoder schrieb:

Quote

> im using Delphi 4
> i wanna create new 100x100 Pixel 256 color bitmap file
> how can i create?

> and then   i wanna put pixel  in the bitmap file

> like this ...
>  mybitmap:=create.bitmap[256 color,100,100 pixel]
>   r:=255;
>   g:=0
>   b:=0;
>   mybitmap.putpixel[50,50,r,g,b];
> end;

> Please help i really need that ...
> thanks for your interests

Other Threads