Android Question (Solved) How to convert image to bitmap? (In-Line Java code)

LGS

Member
Licensed User
Longtime User
Hello everyone.
I am using itextpdf to create a pdf, and everything works fine.
In addition to this I need to convert the image to bitmap, so that it is returned in the function.

B4X:
public void draw128(String filename,String ruta) throws IOException, DocumentException {
        
        String configFilePath = ruta;
        Document document = new Document(new Rectangle(340, 842));
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(configFilePath + filename));
        document.open();
        PdfContentByte cb = writer.getDirectContent();
          
        Barcode128 uccEan128 = new Barcode128();
        uccEan128.setCodeType(Barcode.CODE128_UCC);
        uccEan128.setCode("(01)00000090311314(10)ABC123(15)060916");

        Image imagetoConvert = uccEan128.createImageWithBarcode(cb, BaseColor.BLACK,BaseColor.BLACK);

        document.add(imagetoConvert);
        document.close(); 'The pdf file is successfully created
          
          // HOW CONVERT imagetoConvert to Bitmap?
          // Bitmap bitmaptoReturn = ???????
          // return bitmaptoReturn;         
}

I appreciate all the support
 

Attachments

  • CB.zip
    10.9 KB · Views: 182

LGS

Member
Licensed User
Longtime User

You are right drgottjr, @JohanSchoeman guided me until I found the solution.
I tried to create the code with zxing, but I could only create standard CODE-128, not GS1, which is a special form of CODE-128.
I appreciate your comments
 
Upvote 0

LGS

Member
Licensed User
Longtime User

Mr. Schoeman we did...
In B4A, Canvas is different than B4J
Canvas is not a view (like in B4J). It is an object that draws over other views.
With some adjustments to your suggestion I was able to create the image in .png

B4X:
    For i = 0 To mybytes.Length - 1
        If i Mod 2 = 0 Then
            Dim Rect1 As B4XRect
            Rect1.Initialize(lft, 10dip, (barwidth * mybytes(i))+lft, 80dip)
            Canvas1.DrawRect(Rect1,xui.Color_Black,True,1)
'            Canvas1.DrawRect(lft, 10dip, barwidth * mybytes(i), 80dip, Colors.Black, True, 0)
        Else
            Dim Rect2 As B4XRect
            Rect2.Initialize(lft, 10dip, (barwidth * mybytes(i))+lft, 80dip)
            Canvas1.DrawRect(Rect2,xui.Color_White,True,1)
'            Canvas1.DrawRect(lft, 10dip, barwidth * mybytes(i), 80dip, fx.Colors.White, True, 0)
        End If
        lft = lft + (barwidth * mybytes(i))
    Next

I really appreciate your time and support.
 
Upvote 0

Johan Schoeman

Expert
Licensed User
Longtime User
Glad it is working for you.
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
I can scan it with my wrapped ZXing library.
scanning doesn't seem to be the problem, and op didn't exactly answer my question: was the code that i generated with GS1_FORMAT on a GS1? or just a barcode128? i don't know how to tell the difference, and op basically repeated what he had said previously (that he wasn't able to generate a GS1.) he didn't say whether he set GS1_FORMAT on or not. but so long as he is satisfied, that's what counts.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…