B4J Question Store image to SQLite (from HTMLeditor and Clipboard)

ThRuST

Well-Known Member
Licensed User
Longtime User
I want to store an image into a SQLite database using B4J and also load it back, let's say the image is in a HTMLeditor1 control. Store an image directly from the clipboard is also an option I would like to cover. Any advice on how it's done?

I zipped up my small source code example for you to play around with post your changes as a zip thanks. You will also get my B4JUtils library as a code module. It makes it very easy to create/access the application folder and subfolders.

btw the loaded byte array should show the image in ImageView2.

Solution in v1.1 Thanks to MarkusR for providing help for the solution. Erel contributed with help as well.

v1.2 contains the new improved code provided by Erel and MarkusR. Check it out :)
 

Attachments

  • BLOB.zip
    92.6 KB · Views: 328
  • BLOB v1.1.zip
    94.7 KB · Views: 322
  • BLOB v1.2.zip
    94.8 KB · Views: 370
Last edited:

MarkusR

Well-Known Member
Licensed User
Longtime User
i am new to B4X but here a example
i copy a image from paint into Clipboard
B4X:
    Dim stream As OutputStream
    stream.InitializeToBytesArray(0)
  
    Dim Image1 As Image
    Image1 = fx.Clipboard.GetImage()
    Image1.WriteToStream( stream )
  
     Dim Buffer1() As Byte = stream.ToBytesArray

    stream.Close

    Log(Buffer1.Length)
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
@MarkusR Works nicely, great :) As long as Master Erel or some of the other gurus does not come up with a better solution I rest my case :) Cheers
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
oh, I forgot from the HTMLeditor haha just to bug you further @MarkusR. Save an image from HTMLeditor to file, THAT is the hard bonus question ;)
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
see also
B4X:
fx.Clipboard.HasImage

not used this HTMLEditor but it have a HTMLEditor1.Snapshot
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
The thing is, when saving from the HTMLeditor control you save as HTMLtext, which wrapps the image in some HTML code. This has been bugging me for a long time how to only store the image, in case there's just an image in the HTMLeditor view. It's possible to take a snapshot, so I guess that might be the solution. The magic wil lthen be to know the size of the image. EDIT : so when the HTMLtext is loaded back, it needs to be put in the HTMLeditor control to view correctly. If pasted into Word for example, there will be HTML surrounding the image name only, which is not what we want :)
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
The magic wil lthen be to know the size of the image.
B4X:
    Dim Img As Image = HTMLEditor1.Snapshot
    Log(Img.Width & " x "& Img.Height)
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
That will include formatting for text font size etc as well? have you tested it? What if there's two images? haha I am pushing my luck here, please don't go upset. Excuse me for my lack of knowledge :)
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
i guess you well extract only the content images from HTMLEditor1 ...
i not played with but if i found a solution i post here.
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
Thanks, I could not try it in the source code example because somehow the HTMLeditor webview won't allow focus. Tried to run both in debug and release mode same thing.
I assume your solution will work to put an image from HTMLeditor into ImageView1 in the source, but I cannot test it so I'll leave it at that.

B4X:
Sub Button1_Click
    
    'InsertBlob
    
    Dim Img As Image = HTMLEditor1.Snapshot
    Log(Img.Width & " x "& Img.Height)
    
    ' Set nbew image in ImageView1
    ImageView1.SetImage(Img)
    
End Sub

I think we'll covered this so it will help others as well. It will be very useful for my own project Athena.
You can find my post about it in B4J forum - Share my creations, to see what it's all about. Cheers :)
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
a normal html page have only a reference to images, i think you can get this with regular expressions from the html source code.
then u need Okhttputils to "download" image from uri one by one.
OT:Athena looks like a code snippet database for me.
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
Intersting idea. I should try the snapshot with HTMLeditor again and try to locate the problem ,it might be useful to use snapshot with storing of images. Athena's document manager is to be correct a knowledge framework to store documents that can hold text and images about any category. There's a programmable contextmenu that supports Code, HTML, Folders, Programs, Weblinks and... soon Images ;) so I wanted to cover this properly to be able to add support for storing/retrieving images in the contextmenu. There will be alot more baked in, so it's not only one application because of the concept I have to keep my innovative mind open but code snippets yes, as well as a way for the common user to interact with the computer system. Software development is a huge area, and the idea is that only working solutions will be available in server mode. That means, no questions only answers. In local mode you can store anything, even passwords to recruitment companies, dev sites, general accounts and so on. You should buy a 9-buttoned mouse because it will make it smooth to toggle between the floating menus, as there's four of them, 30 rows * 4 menus. And there's 4 database banks which gives a total of 120 * 4 = 480 slots for code snippets, folders shortcuts, shortcuts to programs, Weblinks.. and soon also images. Ambitious project so I gotta get to work :)
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
The 9 buttoned mouse device I use is this. Highly recommended. The two topleft buttons cycles floating menus white middle mouse counts menus up by one every click. The right button shows the contextmenu. Which can be turned on and off in settings in Athena. Some quite advertising here, it's only for the better I can tell :)

LogitechG300S.jpg
 
Upvote 0
Top