Storing UIImage in Nano Store In Motion - rubymotion

I have been reading about Nano Store in Motion and it seems I can't store an image in it's database. I have read abound storing images in NSDictionary and then storing that in Nano. Would this work, and if so how do you go about storing an image in a NSDictionary function.

This may be of benefit:
How can I store a UIImage in an NSDictionary?
RubyMotion-ized:
dict = NSMutableDictionary.dictionaryWithCapacity(1)
img = UIImage.imageNamed("whatever")
dict["some_key"] = img
extracted_image = dict["some_key"]

You'll need to use a "serializable" value:
from https://github.com/tciuro/NanoStore
The dictionary must be serializable, which means that only the following data types are allowed:
NSArray
NSDictionary
NSString
NSData (*)
NSDate
NSNumber
So in your case, you could create a PNG data representation:
data = UIImagePNGRepresentation(image)
You can store this data in a Hash if you want, but you'll need to convert it back to a UIImage before using it.
image = UIImage.imageWithData(self, scale:UIScreen.mainScreen.scale)

Related

Empty data frame is returned after resolve choice is applied to dynamic frame

I am using resolve choice to convert some columns' datatype to double. Below is the code:
resolved_data = Get_Data_From_Dynamic_Frame_node1655725248083.resolveChoice(specs = [("items[].dimensions[].item.height.value", "cast:double")]).resolveChoice(specs = [("items[].dimensions[].item.length.value", "cast:double")]).resolveChoice(specs = [("items[].dimensions[].item.width.value", "cast:double")]).resolveChoice(specs = [("items[].dimensions[].item.weight.value", "cast:double")])
After this, I convert this dynamic frame to a data frame. The data frame count function return zero and no data is written into s3. Below is the sample data/schema:
Am I missing something? Any help will be highly appreciated.

How to save json data in bigtable? [duplicate]

I would like to insert a json object into a Hbase cellusing scala, presently i'm able to insert values using the below code but would like to know how i may be able to insert the entire Json object into a Hbase cell.
import org.apache.hadoop.hbase.util.Bytes.toBytes
val hTable:HTable = new HTable(configuration, "tablename")
val p = new Put(Bytes.toBytes("row1"))
p.add(Bytes.toBytes("info"),Bytes.toBytes("firstname)",Bytes.toBytes("Jim"))
hTable.put(p)
hTable.close()
You can encode your json object as a string. then encode this string as byte array. then put this byte array in Hbase. pseudo code will be like this:
json = createYourJson()
jsonString = json.toString
jsonBytyes = Bytes.toBytes(jsonString)
put.add(yourColumnFamily, yourQualifier, jsonBytes)
and when loading the value from hbase you have to reverse this order. Pseudo code will be like this:
jsonBytes = hbase.get(table, columnFamily, qualifier)
jsonString = Bytes.toString(jsonBytes)
json = Json.parse(jsonString)

Converting binary value to string and back to binary?

I have rowversion value that comes from Database in binary format. I need to convert that value to string in order to pass in my front-end code. Then when user submits data back to the server I need to convert that string back to binary. Here is example of my data:
Binary 00000010586
Above output is what I see when my query result returns value. Then I tried this:
Encoded value looks like this: iV
Then I tried to decode value back and this is what I have used:
#charsetDecode( local.encodedVal, "utf-8" )#
Then I got this error message: ByteArray objects cannot be converted to strings.
In my database row version column has timestamp type. When query returns that value it's represented as binary in ColdFusion. I use this column as unique id for each row set in my table. Is there a way to handle this conversion in CldFusion adn what would be the best approach?
Your working with binary data, and not with string encodings. You will need to use binaryEncoded and binaryDecode to send your data as a string and convert it back to binary.
The following example converts some binary data into 2 string representations and converts them back into the same byte array with binaryDecodein the dump.
<cfscript>
binaryData = toBinary("SomeBinaryData++");
hexEncoded = binaryEncode(binaryData, "hex");
base64Encoded = binaryEncode(binaryData, "base64");
writeDump([
binaryData,
hexEncoded,
base64Encoded,
binaryDecode(hexEncoded, "hex"),
binaryDecode(base64Encoded, "base64")
]);
</cfscript>
Run the example on TryCF.com

compare two dictionary and display the image based on the key in python

How can i compare two dictionary and based on the matching keys I have to display the images. I mean if the key matched with the first dictionary and its in the second too, then i have to take the image based on the key. I have given a try, and the code is:
for key in res_lst_srt:
if key in resizedlist:
b,g,r = cv2.split(images[i])
img = cv2.merge((r,g,b))
plt.subplot(2,3,i+1),plt.imshow(img)
plt.xticks([]),plt.yticks([])
plt.show()
I have taken the query image seperately, and i have got the distance between the query image,and all the database image. Distance have key and value, database image have key and value. I want to retrieve the image which matches the best with minimum distance based on key.
Thanks in advance!
It seems to me that you are not properly into the dict concept, you should study it a little bit to understand how it works with simple elements (number, strings) and only when you got it try with the heavy datas as opencv images.
Try this piece of code:
dict1 = {'a':1, 'b':2, 'c':3}
dict2 = {'e':1, 'd':2, 'c':4}
print dict1
print dict2
# note that this code is not optimized!!
# there are plenty of ways you can do better
# but prob. is the easiest way == better way to understand it
for k1 in dict1.keys():
for k2 in dict2.keys():
if k1==k2:
print 'keys matches'
mergedvalues = dict1[k1] + dict2[k2]
print 'merged value is:', merged values
for better ways to compare two dicts going deep in python way of handling dict and other data structures (as list, set, etc) and operations on that, this answer is nice. but I think you should understand how dict works before.

<Binary> in sql

I want to select all the binary data from a column of a SQL database (SQL Server Enterprise) using C++ query. I'm not sure what is in the binary data, and all it says is .
I tried this (it's been passed onto me to study off from) and I honestly don't 100% understand the code at some parts, as I commented):
SqlConnection^ cn = gcnew SqlConnection();
SqlCommand^ cmd;
SqlDataAdapter^ da;
DataTable^ dt;
cn->ConnectionString = "Server = localhost; Database=portable; User ID = glitch; Pwd = 1234";
cn->Open();
cmd=gcnew SqlCommand("SELECT BinaryColumn FROM RawData", cn);
da = gcnew SqlDataAdapter(cmd);
dt = gcnew DataTable("BinaryTemp"); //I'm confused about this piece of code, is it supposed to create a new table in the database or a temp one in the code?
da->Fill(dt);
for(int i = 0; i < dt->Rows->Count-1; i++)
{
String^ value_string;
value_string=dt->Rows[i]->ToString();
Console::WriteLine(value_string);
}
cn->Close();
Console::ReadLine();
but it only returns a lot of "System.Data.DataRow".
Can someone help me?
(I need to put it into a matrix form after I extract the binary data, so if anyone could provide help for that part as well, it'd be highly appreciated!)
dt->Rows[i] is indeed a DataRow ^. To extract a specific field from it, use its indexer:
array<char> ^blob=dt->Rows[i][0];
This extracts the first column (since you have only one) and returns an array representation of it.
To answer the question in your code, the way SqlDataAdapter works is like this:
you build a DataTable to hold the data to retrieve. You can fill in its columns, but you're not required to. Neither are you required to give it a name.
you build the adapter object, giving it a query and a connection object
you call the Fill method on the adapter, giving it the previously created DataTable to fill with whatever your query returns.
and you're done with the adapter. At this point you can dispose of it (for example inside a using statement if you're using C#).