Android Question BitmapCreator's Bitmap

DrownedBat

Member
Licensed User
Longtime User
Hi all. Been wrestling with an issue. Trying to create a function that takes a black & white .png file, changes the colors, saves that bitmap to a global bitmap, and then exports that saved bitmap into an SQL database. Mixed results on this one. Either the BitmapCreator's bitmap saves only the original black & white image to the database, or the procedure corrupts the image of the database and destroys it. What I'm working with:

B4X:
Dim bmpTEMP As Bitmap=LoadBitmap(File.DirRootExternal & BoxFrontPath, BoxFrontFile)
Dim bc As BitmapCreator
bc.Initialize(bmpTEMP.Width, bmpTEMP.Height)
'Redraw Image
For i=0 To (bmpTEMP.height-1)
    For j=0 To (bmpTEMP.Width-1)
        If bmpTEMP.GetPixel(j, i)=Colors.RGB(255,255,255) Then bc.SetColor(j, i, Colors.Transparent)
        If bmpTEMP.GetPixel(j, i)=Colors.RGB(0,0,0) Then bc.SetColor(j, i, DarkColor)
    Next
Next
bc.SetBitmapToImageView(bc.Bitmap, imgDark)
AddBMP03.Initialize(File.DirAssets, "Blank.png")
AddBMP03=imgDark.Bitmap

In the example here, I'm converting the white areas of the black & white original to transparent, and converting the black areas to "DarkColor". bmpTEMP holds the original black & white image. I'm using a globally-declared bitmap (AddBMP03) to transfer the altered bitmap to the subroutine that saves it to the database. It is first initialized using an empty bitmap ("Blank.png"). For some reason, I can see that the bc does its job and changes the color. When running the program, imgDark (the ImageView that displays the results) does indeed show the altered color version. I'm having a rough time transferring the newly-colored bitmap into AddBMP03. So far, all that ends up being transferred into that is the black & white original. How can I export the bitmap locked within bc.bitmap to the global bitmap AddMBP03?
 

teddybear

Well-Known Member
Licensed User
B4X:
Dim bmpTEMP As Bitmap=LoadBitmap(File.DirRootExternal & BoxFrontPath, BoxFrontFile)
Dim bc As BitmapCreator
bc.Initialize(bmpTEMP.Width, bmpTEMP.Height)
'Redraw Image
For i=0 To (bmpTEMP.height-1)
    For j=0 To (bmpTEMP.Width-1)
        If bmpTEMP.GetPixel(j, i)=Colors.RGB(255,255,255) Then bc.SetColor(j, i, Colors.Transparent)
        If bmpTEMP.GetPixel(j, i)=Colors.RGB(0,0,0) Then bc.SetColor(j, i, DarkColor)
    Next
Next
bc.SetBitmapToImageView(bc.Bitmap, imgDark)
AddBMP03.Initialize(File.DirAssets, "Blank.png")
AddBMP03=imgDark.Bitmap
How can I export the bitmap locked within bc.bitmap to the global bitmap AddMBP03?
AddBMP03.Initialize(File.DirAssets, "Blank.png")
It is useless, later you have assigned AddBMP03 a reference to imgDark.Bitmap. it should be same as bc.Bitmap.
 
Last edited:
Upvote 0

emexes

Expert
Licensed User
I'm keeping an eye on this thread because I'm interested in a related topic: how to do basic graphics with discrete square pixels, without pixel and line RGB colors being altered by antialiasing.
 
Upvote 0

Knoppi

Active Member
Licensed User
Longtime User
Try this
B4X:
Private Sub Test
    Dim bmpTEMP As Bitmap=LoadBitmap( BoxFrontPath, BoxFrontFile)
    ivOrig.Bitmap = bmpTEMP
    Dim bc As BitmapCreator
    bc.Initialize(bmpTEMP.Width, bmpTEMP.Height)
    'Redraw Image
    For i=0 To (bmpTEMP.height-1)
        For j=0 To (bmpTEMP.Width-1)
            If bmpTEMP.GetPixel(j, i)=Colors.RGB(255,255,255) Then bc.SetColor(j, i, Colors.Transparent)
            If bmpTEMP.GetPixel(j, i)=Colors.RGB(0,0,0) Then bc.SetColor(j, i, DarkColor)
        Next
    Next
    ivDark.Bitmap = bc.Bitmap
    AddBMP03.Initialize3( ivDark.Bitmap)
    ivNew.Bitmap = AddBMP03
End Sub
 

Attachments

  • bitmap.zip
    43 KB · Views: 37
Upvote 0

DrownedBat

Member
Licensed User
Longtime User
AddBMP03.Initialize(File.DirAssets, "Blank.png")
It is useless, later you have assigned AddBMP03 a reference to imgDark.Bitmap. it should be same as bc.Bitmap.
Correct, it is useless for this subroutine, but the subroutine that handles recording the image into the database is separate, so I need to bridge the image between the two, so I set it into the global bitmap and then pull from that.
 
Upvote 0

DrownedBat

Member
Licensed User
Longtime User
Try this
B4X:
Private Sub Test
    Dim bmpTEMP As Bitmap=LoadBitmap( BoxFrontPath, BoxFrontFile)
    ivOrig.Bitmap = bmpTEMP
    Dim bc As BitmapCreator
    bc.Initialize(bmpTEMP.Width, bmpTEMP.Height)
    'Redraw Image
    For i=0 To (bmpTEMP.height-1)
        For j=0 To (bmpTEMP.Width-1)
            If bmpTEMP.GetPixel(j, i)=Colors.RGB(255,255,255) Then bc.SetColor(j, i, Colors.Transparent)
            If bmpTEMP.GetPixel(j, i)=Colors.RGB(0,0,0) Then bc.SetColor(j, i, DarkColor)
        Next
    Next
    ivDark.Bitmap = bc.Bitmap
    AddBMP03.Initialize3( ivDark.Bitmap)
    ivNew.Bitmap = AddBMP03
End Sub
That's got it. Initialize3 allows me to skip the middle man and successfully records the preview image into the global bitmap.
 
Upvote 0
Top