qml qt grabToImage get image bytes - image

For some reason, saving a png back out from qml directly doesn't work. I have a qml UI on top of a Golang application. When I do
source.grabToImage(function(result){
console.log("image: ", result.url)
if (!result.saveToFile(urlNoProtocol)){
console.error('Unknown error saving to',urlNoProtocol);
} else {
console.log("saved to " + urlNoProtocol)
}
I get an error saving out. The location to save the file is coming from a fileDialog and I preprocess it to remove the file:// which I understand needs to be removed before using saveToFile. However I get an unknown error saving from the above code.
I suspect this is something to do with the qml being embedded in the binary application (perhaps to do with qrc:// or something)
Anyway my current plan is to send the image to the golang backend and save it out from there, so my question is, how from grabToImage or saveToFile can I get the image bytes that I will then save?
N.B Using therecipe/qt for the interface between Golang and qml

I have used this method for grabbing screen shots..
function performScreenShot(item, name) {
if(typeof(item) === "undefined") {
return;
}
else if(typeof(name) !== "string") {
name = "screenshot.png"
}
item.grabToImage(function(result) {
result.saveToFile(name);
});
}
Usage example:-
performScreenShot(main, "screenshot-" + screenShotIndex + ".png")
Where main is my object id and screenShotIndex is something im incrementing so as not to override any previous capture.
Ensure that you have write permission on the device.

Related

UWP won't compile GetBufferFromString in Microsoft example for FileIO.WriteBufferAsync

I'm trying to use WriteBufferAsync in the Microsoft example for FileIO.WriteBufferAsync but GetBufferFromString doesn't compile.
Ultimately, I want to write a byte buffer to an absolute file path.
This is a copy from the example...
try
{
if (file != null)
{
IBuffer buffer = GetBufferFromString("Swift as a shadow");
await FileIO.WriteBufferAsync(file, buffer);
// Perform additional tasks after file is written
}
}
// Handle errors with catch blocks
catch (FileNotFoundException)
{
// For example, handle file not found
}
GetBufferFromString doesn't compile.
#Raymond Chen's comments are very convincing. And he is the author of the UWP official code sample. The reason why GetBufferFromString could not be compiled is you have not declared it.
private IBuffer GetBufferFromString(String str)
{
using (InMemoryRandomAccessStream memoryStream = new InMemoryRandomAccessStream())
{
using (DataWriter dataWriter = new DataWriter(memoryStream))
{
dataWriter.WriteString(str);
return dataWriter.DetachBuffer();
}
}
}
I want to write a byte buffer to an absolute file path.
For writing a buffer to an absolute file path, you could use PathIO.WriteBufferAsync method. Please note, you need make sure your file could be accessed within uwp. for example, if your file stored in picture library, you need add Picture capability. for more detail please refer UWP file access permissions.

Unable to find object at PDF cross-reference stream location. (abcpdf)

I am getting below error when processing the single page pdf.
May i know why i am getting this error
Doc theSrc = new Doc();
theSrc.Read(e.FullPath); on this line
Unable to find object at PDF cross-reference stream location.
Thanks,
If you use ABCpdf's ExtraChecks feature that would give you the option to either try and get ABCpdf to fix the corruption, or have your own application/site issue a warning that the PDF is corrupt.
Of course there are limits to what ABCpdf can fix - in that case you would still end receiving an error from ABCpdf.
In terms of code, the logic would be something like this:
try
{
doc.Read(inFile);
// No corruption detected
doc.Save("good.pdf");
}
catch
{
try
{
doc.Read(inFile, new XReadOptions { ExtraChecks = true });
// ExtraChecks managed to fix the corruption
doc.Save("fixed.pdf"));
}
catch
{
// ABCpdf could not fix the corruption
}
}

Cocoa ITLibrary - ITLibMediaItem.location always nil/NULL

I am getting always nil ITLibMediaItem.location attribute.
// let library: ITLibrary = try ITLibrary(APIVersion: "1.0")
// library.reloadData()
if let mediaItem = iTuneMediaItem {
if let location = mediaItem.location{
return location.path
}else{
print("nil location")
}
}else{
print("nil mediaItem")
}
If i enable commented line to reload library before get location it is working, but i don't want to reload library every time because it takes time if we have large iTunes playlist.
can please anyone explain how we can fix without reloading library every time?
EDIT :
I am using ITLibMediaItem from ITLibPlaylist.items[]
I figure the fix is need to make static app level attribute of ITLibrary and reload once at init.

Parse Quick Start with YUN

i'm tring to start with YUN and Parse with first example:
ParseObjectCreate create;
create.setClassName("TestObject");
create.add("foo", "bar");
ParseResponse response = create.send();
Serial.println("\nResponse for saving a TestObject:");
Serial.print(response.getJSONBody());
if (!response.getErrorCode()) {
String objectId = response.getString("objectId");
Serial.print("Test object id:");
Serial.println(objectId);
} else {
Serial.println("Failed to save the object");
}
response.close(); // Do not forget to free the resource
When i lauch RUN i obtain only:
Test object id:
without any other else.
What could be the problem?
Thanks
NR
My experience was that I needed to run the "setup" Arduino sketch (just once) to get the Linux side properly configured. After that I could run the sample scripts repeatedly with success.

displaying images from an ArrayCollection in ListItemRenderer in flex

I am facing the following problem,
I have an object called "data". It has three properties, one of it being itemRendererData. The "itemRendererData" is an ArrayCollection of objects having many properties one of which is the property "imageURL" (datatype:String).
I am working in flex. I have defined the view and the item renderer properly. The view has the data. I am supposed to get the images from the url specified by imageURL property.
In the itemRenderer, I have declared, source
source = {data.itemRendererData.imageURL}
But the images are not being displayed.
Use a the FlexEvent.DATA_CHANGE handler rather than binding, which is actually the proper way to handle this and gives you far more control.
public function CustomItemRenderer() {
this.addEventListener(FlexEvent.DATA_CHANGE, this.dataChangeHandler);
this.addEventListener(FlexEvent.CREATION_COMPLETE, this.creationCompleteHandler);
}
private function creationCompleteHandler(e:FlexEvent) {
if (this.data) {
this.image.source = this.data.itemRendererData.imageURL;
}
}
private function dataChangeHandler(e:FlexEvent) {
if (this.data && this.initialized) {
this.image.source = this.data.itemRendererData.imageURL;
}
}
You will notice that I have a handler for FlexEvent.CREATION_COMPLETE as well. This is because the data is actually set before the components are created. So the first time a renderer is loaded, this.image is null and this.image.source will error out.
If that doesn't work, you also need to make sure that the Image/BitmapImage is not a direct child of the renderer. I never did figure out why this was, but adding it as a child of Group fixed that issue where the image was being set but not rendering. Again, I have no idea why this was and I tested for a few hours trying to figure it out.
As an added tip, avoid MXML-based ItemRenderers in mobile applications. They are noticeably slower than pure-AS3 renderers.

Resources