Christo
Christo

Reputation: 411

XE5 Android Bitmap.canvas

I am trying to do custom drawings on TImage using the Bitmap.Canvas property. On Windows the following code works correct to clear the entire Bitmap with a blue fill:

Image1.Bitmap := TBitmap.Create;
 with Image1.Bitmap do
 begin
   width := Round(Image1.Width);
   height := Round(Image1.Height);
   with canvas do
   begin
     BeginScene;
           Clear(TAlphaColorRec.Blue);
     EndScene;
   end;
  end;

On Android the Bitmap is still filled with blue, but it shrieked inside the TImage. How do I do this on an Android device?

Upvotes: 2

Views: 2382

Answers (4)

XWiśniowiecki
XWiśniowiecki

Reputation: 1843

For Android device I heard from Embarcadero specialists that you should draw on custom created TBitmap and then assign it to the drawed component's Canvas.

There is a good video on YouTube that show how to draw pixels in a paintbox:

Video

Upvotes: 1

Remi
Remi

Reputation: 1299

Create bitmap like this:

Image1.Bitmap:=TBitmap.Create(Round(Image1.Width), Round(Image1.Height));

instead of this:

Image1.Bitmap := TBitmap.Create;

Upvotes: 0

wahm sarab
wahm sarab

Reputation: 91

first, is Image1 a designe time component is so ,No need to create a bitmap for it, you just may resize it if you want, i think this was the problem

This code worked with me perfect on android

///////////////////////////////////////////////////////////

image1.bitmap.SetSize(512,512);
if image1.bitmap.Canvas.BeginScene() then
try
  image1.bitmap.Canvas.Clear(TAlphaColorRec.Blue);
finally
  image1.bitmap.Canvas.EndScene;
end;

///////////////////////////////////////////////////////////

Upvotes: 0

Ahmed Ekri
Ahmed Ekri

Reputation: 4651

to create bitmap

Bitmap newBitmap = Bitmap.createBitmap(width, heigth, Config.ARGB_8888);

then you should create a canvas and set it to the bitmap

Canvas cc = new Canvas(newBitmap);

then you make new paint and set to the color wanted

Paint red = new Paint();
red.setColor(android.graphics.Color.RED);
red.setStyle(Paint.Style.FILL);

then you set the paint and bitmap to canvas

  cc.drawBitmap(newBitmap, 0, 0, red);

Upvotes: 0

Related Questions