Recent

Author Topic: Crash in app  (Read 1303 times)

biologic

  • New Member
  • *
  • Posts: 17
Crash in app
« on: March 23, 2025, 04:11:10 am »
Maybe someone more experienced in LAMW can help.

Many thanks.
« Last Edit: April 18, 2025, 10:28:42 pm by biologic »

biologic

  • New Member
  • *
  • Posts: 17
Re: Crash in app
« Reply #1 on: March 23, 2025, 05:59:52 pm »

The code I want to make is :

- Open a bitmap with a press on a button (done)
- Show rhe bitmap on the form (done)
- with a press on 'convert' button, change the pixels to grayscale of the opened bitmap,
and show the changed bitmap on the form.
- with a press on the 'save' button, save this new gray bitmap.

I'm stuck in step 3, convert bitmap to grayscale.

biologic

  • New Member
  • *
  • Posts: 17
Re: Crash in app
« Reply #2 on: March 28, 2025, 11:49:01 pm »
I Found a good resource on Bitmaps in one of the AppDrawingInBitmap examples.

https://en.proft.me/2017/08/2/how-work-bitmap-android/

biologic

  • New Member
  • *
  • Posts: 17
Re: Crash in app
« Reply #3 on: March 30, 2025, 07:21:55 pm »

Anyone knows how to read/write a pixel from a jBitmap/jCanvas ?


dseligo

  • Hero Member
  • *****
  • Posts: 1496
Re: Crash in app
« Reply #4 on: March 31, 2025, 10:37:10 am »
I don't have time to test it now, but ...

Try to use BitmapToArrayOfJByte method, something like:
Code: Pascal  [Select][+][-]
  1. var
  2.   posX, posY, bitmapWidth, bitmapHeight, bytesByLine: Word;
  3.   red, green, blue: Integer;
  4.   ABmp: jBitmap;
  5.   baBmp: TDynArrayOfJByte;
  6.   iNumPixels: Integer;
  7. begin
  8.   ... // load image to ABmp
  9.   ...
  10.   bitmapWidth := ABmp.GetWidth();
  11.   bitmapHeight := ABmp.GetHeight();
  12.   bytesByLine := Ceil(bitmapWidth / 8);
  13.   baBmp := nil;
  14.   iNumPixels := ABmp.BitmapToArrayOfJByte(baBmp); // to array in RGBA format
  15.  
  16.   for posY := 0 to bitmapHeight - 1 do // for every row
  17.   begin
  18.     While j < bitmapWidth do // for every column
  19.     begin
  20.       For k := 0 to 7 do // for every bit bit in column byte
  21.       begin
  22.         posX := j + k;
  23.         if posX < bitmapWidth then // it doesn't have to be whole byte at last column
  24.         begin
  25.           // RGB values, I don't need alpha channel (alpha channel is +3)
  26.           red   := Byte(baBmp[ posY * bitmapWidth * 4 + posX * 4 + 0 ]);
  27.           green := Byte(baBmp[ posY * bitmapWidth * 4 + posX * 4 + 1 ]);
  28.           blue  := Byte(baBmp[ posY * bitmapWidth * 4 + posX * 4 + 2 ]);
  29.           ...
  30.           // you can do something now with pixel RGB values
  31.         end;
  32.       end;
  33.       j := j + 8;
  34.     end;
  35.   end;
  36.   ...
  37.   // convert it to new bitmap
  38. end;

I didn't convert back to bitmap, because I am printing to POS printer. I see that methods GetBitmapFromJByteArray and SetByteArrayToBitmap exists, probably you can use them to get bitmap back from byte array.

biologic

  • New Member
  • *
  • Posts: 17
Re: Crash in app
« Reply #5 on: March 31, 2025, 02:52:39 pm »
Thank you.  :)

I will try this as soon as I can.
Next weekend probably.


biologic

  • New Member
  • *
  • Posts: 17
Re: Crash in app
« Reply #6 on: April 06, 2025, 08:03:01 pm »
If I want to call the getPixels method of the Bitmap Java object,
can this be done inside the project code ?

Or

Something different to do ?

Thanks

biologic

  • New Member
  • *
  • Posts: 17
Re: Crash in app
« Reply #7 on: April 09, 2025, 09:57:30 am »
I found a good explanation at Chatgpt.

 

TinyPortal © 2005-2018