Post Reply 
Import JPEG images to HP Prime
08-25-2019, 08:48 PM
Post: #2
RE: Import JPEG images to HP Prime
You can use AFilesB for this. For example:
L1:=AFilesB("image.jpg",0,1000);
will places the first 1000 bytes of the JPG files into a list L1.

I played around with PNG / Base64 stuff some time ago, which worked out very well in the end. Below is some of the code I currently use (created with help from others as shown in linked thread):
Code:
WriteBase64(fname)
BEGIN
  LOCAL fcontent,j,b64str:="",fsize,fiter;
  fsize:=AFilesB(fname);
  IF fsize>9998 THEN // lists can not be longer than 10000, 9999 divides by 3 evenly
    fiter:=IP(fsize/9999);
    FOR j FROM 1 TO fiter DO
      fcontent:=AFilesB(fname,(j-1)*9999,9999);
      b64str:=b64str+Base64String(9999,fcontent);
    END;
    IF FP(fsize/9999) THEN
      fcontent:=AFilesB(fname,fiter*9999,fsize-(fiter*9999));
      b64str:=b64str+Base64String(SIZE(fcontent),fcontent);
    END;
  ELSE
    fcontent:=AFilesB(fname,0,fsize);
    b64str:=b64str+Base64String(SIZE(fcontent),fcontent);
  END;
  RETURN b64str;
END;

Base64String(fsize,mylst)
BEGIN
  LOCAL fiter:=IP(fsize/3),L1,N,j,i,mystr:="";
  LOCAL dict:={"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9","+","/"};
  FOR j FROM 1 TO fiter DO
    N:=mylst(j*3-2)*256^2+mylst(j*3-1)*256+mylst(j*3);
    FOR i FROM 3 DOWNTO 0 DO
      L1:=IP(N/64^i);
      mystr:=mystr+dict(L1+1);
      N:=N-L1*64^i;
    END;
  END;
  IF fsize-fiter*3 THEN // fractional
    IF (fsize-fiter*3)==1 THEN
      N:=mylst(fsize)*256^2;
      FOR i FROM 3 DOWNTO 2 DO
        L1:=IP(N/64^i);
        mystr:=mystr+dict(L1+1);
        N:=N-L1*64^i;
      END;
      mystr:=mystr+"==";
    ELSE // must be 2
      N:=mylst(fsize-1)*256^2+mylst(fsize)*256;
      FOR i FROM 3 DOWNTO 1 DO
        L1:=IP(N/64^i);
        mystr:=mystr+dict(L1+1);
        N:=N-L1*64^i;
      END;
      mystr:=mystr+"=";
    END;
  END;
  RETURN mystr;
END;

Example Use:
Code:
AFiles("tempPNG"):=G0;
b64str:=WriteBase64("tempPNG");
DelAFiles("tempPNG");

Maybe not quite the usage in mind, but some clues hopefully in there somewhere.
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Import JPEG images to HP Prime - Jacob Wall - 08-25-2019 08:48 PM



User(s) browsing this thread: 1 Guest(s)