سؤال

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?

هل كانت مفيدة؟

المحلول

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

نصائح أخرى

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);

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;

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

Create bitmap like this:

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

instead of this:

Image1.Bitmap := TBitmap.Create;
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top