How to print logo (png, jpg)?

Just starting out? Need help? Post your questions and find answers here.
stmdbe2019
User
User
Posts: 89
Joined: Mon Aug 31, 2009 2:11 pm

How to print logo (png, jpg)?

Post by stmdbe2019 »

How to print logo (png, jpg) ?
With following code i am only able to print text in the label printer, where i need to add logo on the sticker. Any idea how it is possible?

Code: Select all

  ElseIf FindString(commands$, "meeting:", 0)
    main_command$ = ReplaceString(commands$, "meeting:", "")
    If Not main_command$ = ""
      ; Font name, font size   
      Dim Font(5)
      Font(0) = LoadFont(-1, "Arial", 26)
      Font(1) = LoadFont(-1, "Arial", 130)
      Font(2) = LoadFont(-1, "Arial", 26)
      
      If DefaultPrinter()         
        If StartPrinting("Test")
          If StartDrawing(PrinterOutput())
            DrawingMode(#PB_2DDrawing_Transparent)
            Info.SYSTEMTIME
            GetSystemTime_(Info)

            ;dmyhm.s = Str(Info\wDay) + "-" + Str(Info\wMonth) + "-" + Str(Info\wYear) + " " + Str(Info\wHour) + ":" + Str(Info\wMinute)
            dmyhm.s = NotepadTimeDate()

            AlignText(10,10, dmyhm + " ||| ABACD", Font(0), #Black)
            AlignText(10,20, "GUEST: You yours", Font(0), #Black)
            AlignText(10,40, "HOST: I you we", Font(0), #Black)
                  
            AlignText(10,320, "____________________________________________________", Font(0), #Black)
            
            StopDrawing()
          EndIf
         
        StopPrinting()
        EndIf 
      EndIf
__________________________________________________
Quote tags>Code tags
12.10.2018
RSBasic
-----
Registered PureBasic Coder.
wombats
Enthusiast
Enthusiast
Posts: 664
Joined: Thu Dec 29, 2011 5:03 pm

Re: How to print logo (png, jpg)?

Post by wombats »

Does DrawImage() not work?
stmdbe2019
User
User
Posts: 89
Joined: Mon Aug 31, 2009 2:11 pm

Re: How to print logo (png, jpg)?

Post by stmdbe2019 »

Thanks. Following way it works, to print logo on sticker.

Code: Select all

UsePNGImageDecoder()
UseJPEGImageDecoder()
UseGIFImageDecoder()

Procedure AlignText(X,YAlign,Text.s,Font,RGB=-1,BackRGB=-1)
   ; ;Without  RGB Param or RGB=-1, keeps previous RGB. Default=#Black
   ; ;Without BackRGB Param or BackRGB=-1, keeps previous BackRGB. Default=#White
   Static X1,Y1,OldRGB,OldBACK
   FontID=FontID(Font)
   DrawingFont(FontID)
   If RGB=-1 : RGB=OldRGB: EndIf
   If BackRGB=-1
        If OldBACK=RGB:BackRGB=#White
        Else :  BackRGB=OldBACK
        EndIf
   EndIf
   If X=-1
        If X1=0:X=0
        Else:X=X1
        EndIf
   EndIf
   If YAlign=-1
        If Y1=0:YAlign=0
        Else:YAlign=Y1
        EndIf
   EndIf

   ; Select the font, Get the Font Metrics, and then reselect the current object
   hOld.l = SelectObject_(_DRAWING,FontID)
   GetTextMetrics_(_DRAWING, TM.NEWTEXTMETRIC)  ;to change text bottom position
   If hOld <> 0 : SelectObject_(_DRAWING,hOld):EndIf
   
   
   
   X1=DrawText(X,YAlign-TM\tmAscent,Text,RGB,BackRGB)
   Y1=YAlign
   
   OldRGB=RGB :  OldBACK=BackRGB
   ProcedureReturn X1 ; x position for the next string
EndProcedure

; simulate
commands$ ="meeting:NAME:iami / Host:your are you"
main_command$ = ReplaceString(commands$, "meeting:", "")
If Not main_command$ = ""
  ; Font name, font size   
  Dim Font(5)
  Font(0) = LoadFont(-1, "Arial", 17)
  Font(1) = LoadFont(-1, "Arial", 50)
  Font(2) = LoadFont(-1, "Arial", 14)
  
  If DefaultPrinter()         
    If StartPrinting("Test")
      If StartDrawing(PrinterOutput())
        DrawingMode(#PB_2DDrawing_Transparent)
        Info.SYSTEMTIME
        GetSystemTime_(Info)

        ;dmyhm.s = Str(Info\wDay) + "-" + Str(Info\wMonth) + "-" + Str(Info\wYear) + " " + Str(Info\wHour) + ":" + Str(Info\wMinute)
        ;dmyhm.s = NotepadTimeDate()
        AlignText(10,150,  main_command$, Font(0), #Black)
        
        If FileSize("fcom.jpg")= -1
          InitNetwork()
          ReceiveHTTPFile("https://i.imgur.com/TAkFrwx.jpg","fcom.jpg")
        EndIf    
        
        img1 = LoadImage(#PB_Any,"fcom.jpg")
        If img1
          width = ImageWidth(img1)
          height = ImageHeight(img1)
          ;ResizeWindow(0,0,0,width,height)
          ;ImageGadget(0,0,0,30,230,ImageID(img1),#PB_Image_Border)  
          DrawImage(ImageID(img1), 10, 10,90,60)
        EndIf 
       
        
        AlignText(10,320, "____________________________________________________", Font(0), #Black)
        
        StopDrawing()
      EndIf
     
    StopPrinting()
    EndIf 
  EndIf
  
EndIf        
-----
Registered PureBasic Coder.
Post Reply