What's is th best way to manage pictures WP 8.1 - c#

Actually I'm developing an "social" app for my office and I'm wondering what's the best way to load or manage pictures. Each user has a profil picture and I would like to display it wherever I want, on the profil view, in the contacts list (little smaller) for example. When the user creates its profil, he picks up a picture from the picture library on his phone and it's send to server as base64 encoded string. The code that I've used to save the picked picture on the server (SQL Server 2012 database):
var reader = new DataReader(pictureStream.GetInputStreamAt(0));
byte[] bytes = new byte[pictureStream.Size];
await reader.LoadAsync((uint)pictureStream.Size);
reader.ReadBytes(bytes);
string bytesString = Convert.ToBase64String(bytes);
So here bytesString contains the base64 encoded picture to send on the server. Atually, I'm facing two problems.
First problem:
The base64 encoded string cannot be inserted to the database even if the column type is varchar(max). The string is cut in the table.
Second problem:
If I want to build the picture from bytesString decoding the base64 string, it takes so much time that it's not possible to work like that.
So I'm wondering how applications such Instagram or other picture specialized application are managing pictures so well... Does anyone could give me some advises to manage pictures through an app ? Thanks in advance !

Two ideas come to mind:
1. Store the images in a binary-type column
I haven't used SQL server very much, but I guess there is a binary column type in which you can just store the original bytes of the image.
2. Store the images in files instead of the database.
Another thing you can do is to simply store the images in files with names based on the users' IDs (i.e. user_15.png).
Other considerations
Is there any reason to encode/decode the bytes? Sending the original image seems like a better option to me.
How are you actually sending the encoded image bytes? From what I understand varchar(max) should be able to hold quite a lot of data. Are you sure the server receives the right data?
On the client (in the WP 8.1 app) you may want to cache the images, so that you wouldn't need to load them from the server every time.

Related

Best way to store text in UWP application

I'm quite new to programming.
I'm making an UWP application, and on one of the pages I want to display a bunch of laws and regulations.
Where should I store the text/paragraphs?
I do not want to write them all in the XAML file, as this will take a lot of space and make
the XAML file hard to navigate and read.
I know it's possible to store text-strings in a resource file (.resw), but for me it seems like this is made for storing strings in different languages.
Should I store the strings in a database, SQL? I have not worked with databases before but
I'm eager to learn it if that's the way to go.
I have added a picture of what the law-paragraphs looks like (the text is in norwegian).
The paragraphs will be displayed in different frames on the page. It would be nice if I could easily add and edit text in the database.
Paragraphs
Best way to store text in UWP application
You have many ways to store the text, you could create txt file in your local folder and write the text in it, and here is document how to read and write data into file.
I checked your law-paragraphs, it's not very long string, so you could use LocalSettings to store this law-paragraphs with specific key quickly. Each setting can be up to 8K bytes in size and each composite setting can be up to 64K bytes in size. For more info please refer this document.
And we don't suggest your store this simple law-paragraphs string with SQL, it's too heavy, if you do want it, please refer Use a SQLite database in a UWP app

Best and fastest way to store sensor data in C# UWP app

I have a custom sensor, connected via Bluetooth, that streams data to my UWP app.
I need to store this data locally somehow, however my problem is that it is streaming at 100Hz, so the data is arriving at the app very quickly.
I have tried to store the data into a SQLite database, as it will be easier to work with the data later. e.g. searching the data.
However the SQLite database cannot keep up with the data stream and starts to lag behind considerably overtime.
So does anyone have any advice or recommendations to the best approach for storing large amounts of data very quickly in C# UWP apps?
Many thanks for the help.
You should store data in file instead of sqlite, just append data to file each time. You can use csv or tab separated format. for improving performance save data in batches.
create two array of objects.
imported data will be added to one array.
once array is full save that array and new input will be added to other array. you should continues switch between them when one of them is full. and save them(it is like two buffer)

Storing references to images in SQL Server using ASP.NET and C#

I am trying to store references of images in a SQL Server DB and store the actual images in a file server/folder. I am hoping someone could give me a link or code example on how to do this. I don't want to store BLOB in the database.
I am using ASP.NET/C# to handle this.
All files in a folder have unique names, so I think you shouldn't worry about storing the path of the image, as suggested in the comments. If you are worried about consistence, i.e. someone deleting a "referenced" image or inserting a path to nonexistent image file, you could check that either from your application, or even from the database itself.
However I would not hesitate to use a blob, you can use MS SQL 2012 and insert the image files to a file table, which sounds quite convenient.
as per my knowledge.or my expirence the images are stored in sql server that is in image datatype feild.it is stored in byte format.that is actlly the reference of the actual image.hope this link help you to get more clear idea about it
http://www.sqlhub.com/2009/03/image-store-in-sql-server-2005-database.html
http://www.codeproject.com/Articles/10861/Storing-and-Retrieving-Images-from-SQL-Server-usin
Use a HttpHandler to grab the image from the database and use the Image data type:
Retrieve image of image control as byte array which is set using generichandler(.ashx)?
Storing images in your dataase or in a filestream, totaly depends on your images size. In Microsoft Research there is a good paper called To BLOB or Not To BLOB.
After a lot of test and much analysis;
If your pictures are below 256K, store them in datebase VARBINARY column is good.
If your pictures are over 1 MB, storing them in the filesystem is good.(With FILESTREAM attribute, they are still under transactional control and part of the your database)

MS Access, SQL Server image field

I have spent nearly 2 days in trying to figure this out. We have an Access Project (adp) from Year 2000 that stores images to SQL Server 2008. I have tried connecting directly to SQL Server and to open TIFF files but it didn't work. Also tried to copy/paste the image field content into a file, renaming as TIFF and trying to open it but it didn't work as well. The problem with the content in the image field is that it is not of the right size. It is only 15-20KB but the files at that point should be around 3MB. It works fine if I retrieve the same data back in to the ACCESS project application.
I have tried TiffLib.net and few other things.
So, has anyone got any idea on how to migrate those image fields into SQL?
Thanks
Well the Image data type stores a binary version of your image.
Now the conversion process is explain in the below links.
You'll need to use a library to convert a byte array into image object.
http://www.akadia.com/services/dotnet_load_blob.html
http://www.dreamincode.net/forums/topic/103960-save-and-retrieve-images-with-sql-server/
Hopefully this helps.

getting images out of mssql in C# using streams

I have a database which stores .png images as the sql "image" type. I have some code which retrieves these images as a byte[], and sends them to the page via the FileContentResult object in .Net. Performance is key in this application, and the images have to be retrieved and displayed as quickly as possible. My question is, can this operation be performed quicker by passing a byte stream from the database to the browser, and not at anytime storing the whole byte array in memory. If this is possible and worthwhile doing, how do I do it?
Here is the code I have so far:
// Get: /Image/Get/5
public FileResult Get(int id)
{
Response.Cache.SetExpires(DateTime.Now.AddSeconds(300));
Response.Cache.SetCacheability(HttpCacheability.Public);
Response.Cache.SetValidUntilExpires(true);
// Get full size image by PageId.
return base.File(page.getFullsizeImage(id), "image/png");
}
And
public byte[] getFullsizeImage(int pageId)
{
return (from t in tPage
// Filter on pageId.
where t.PageId == pageId
select t.Image).Single().ToArray();
}
Thanks for any help!
A nice question.
Reality is the code required to send the image as a stream is really minimal. It is just Response.Write~~~ byte array and setting the HTTP's content-type header which must be very fast.
Now you seem to need to open up your database to the world to get it done quicker. That, being probably possible using features that allow SQL server to serve HTTP/interact with IIS (long time ago I looked at it), not a good idea so I do not believe you should take that risk.
You are already using the caching so that is cool but files being large, cache gets purged frequently.
But one thing to do is to have a local File Cache on the IIS and if image is used, it is written to the file on teh web server and from then on (until maybe next day when this is cleared) this other URL (to the static asset) is returned so requests would not have to go through the ASP.NET layer. It is not a great idea but will achieve what you need with least risk.
Changing the linq from single to first should give you nicer SQL, if PageId is the primary key you can safely assume first and single will return the same result.
Edit: Based on your comments, I think you should consider using DeepZoom from microsoft. Essentially, what this allows you to do is generate a specialized image file on the server. When a user is browsing the image in full view, just the couple of million or so pixels that are displayed on the screen are sent to the browser via AJAX. Then when the user zooms in, the appropriate pixels for the zoom level and x and y axis are streamed out.
There is a DeepZoom Composer which can be accessed via the command line to generate these image files on demand and write them to a network share. Your users will be really impressed.
Take a look at this example. This is a massive image - Gigabytes. in about the middle of the image you will see some newspaper pages. You can zoom right in and read the articles.
End of Edit
Do you have to have images with a large file size? If they are only meant for displaying in the browser, they should be optimized for the web. All main image editing applications have this ability.
If you do need the large file size, then you could provide optimized images and then when the user clicks on the image, allow them to download the full file. They should expect this download to take some time.
In Photoshop, the task is "Save for web". There is a similarly named plugin for Gimp.
I know that this doesn't answer your direct question ("can this operation be performed quicker by passing a byte stream"), but it might help solve your problem.

Categories