Webclient image upload to server - c#

This is a follow on from my last question (Here) as I don't think I gave enough information the first time around and i can't delete it.
I've got my image converted to a byte array but the follow on help and suggestions made it seem like that the image I wanted to save needed to first exist on my computer. Where, in fact, the image I want to take only exists in the picture box (its a screen grab). When I check my server to see if the image has been passed over, I don't see anything and nothing prompts me to name my image file or anything.
So my question is thus:
What is the best way for my to upload a screen grab from my application, using webclient, to my central server? Ideally the functionality I would like would be very similar to that of saving the image to my computer. The only difference is, it's not my hard drive I'm saving the image on. It's a server somewhere.

Related

Android Mobile: Flex Image control showing missing image

I use a Flex app (SDK version 4.14.1) to take a photo from a camera on Android, and I pass the resulting ByteArray to an .net c# script that writes the image to a directory and sets the name etc.
I can see the file in the file system, I can open the file in the file system (with either a jpg or png extension, I believe that browsers can do this though), but when I add an Image control to Flex and point the source to the path of the image, I just get that annoying missing image icon.
I was guessing that it was to do with extensions, as the image is sent straight from the camera as a byte array I kind of had to guess the extension, but whatever it is can you help me solve it please?
For reference, the image is stored on an IIS web server, but it isn't cross domain policy that is stopping it because if I drag the image into my project and bind it directly it still does the same thing.
Ideally I need to use Image and not BitmapImage, but if it can't be helped then I can change.
Thanks
EDIT
Changing from Image to BitmapImage kind of worked, kind of because the image now shows in the desktop debugger, but on device it just shows blank. Any thoughts on this?
In the spirit of making sure all of my questions get an answer I am going to settle on the solution of using BitmapImage. Every other part of the design is correct, I cannot see anything I am doing wrong, and although using BitmapImage causes me an issue with missing image and placeholder image, it is a solution after all.

Display thumbnails for images in articles

So I have this website where users can post articles, each article containing at least one photo. What I want to do is when I display the list of articles on the website I want to also show a thumbnail next to the articles name.
Here comes the tricky part: the images are not hosted on my server, are simply links hosted on some image-hosting website. Another problem is that I don't know where the images appear in the post (they could be at the beginning, at the end or in the middle of the article).
What would be the best approach to create a thumbnail system in this case?
I was thinking maybe I could do this: every time an article is posted or edited and stored into the database I could scan the entire articles for images links and store the first link in a separate value in the database (this could be kind of slow though).
Also once I have those values stored and I have to display a thumbnail the only way to do so will be by showing the full image resized to the thumbnail size (that means the user has to download multiple full-size images to see the articles list with thumbnails).
Is there any better approach? (you can see the technologies used in the tags)
Create a thumbnails task that runs in the background after an article has been published.
Find image tags in the article HTML using regular expression.
Get those images and create and thumbnail that you save locally in a folder in your server.
Protect that folder/location against hotlinking.
Use those local pictures as thumbnails
Use HtmlAgilityPack as a starter to get to the images from the image host.
Use an ASP.NET handler to generate the thumbnails. That way, you won't have to store anything locally, the thumbnails images will only exist in memory, making hotlinking impossible

Rotating Image in C# Desktop Application from Image Location Only

I am writing a C# desktop application that involves importing images from a digital camera, and saving them in a SQL Compact Edition database. I'm not saving the actual images in the database, but the image file path (to save database space). I'm then pulling that image file path from the database and setting the Image Location property of a Picture Box to that path, for display purposes.
My question is this... I would like to add a button that will allow the user to rotate the image after import. Is there a way to do this without creating a new image? I know of the RotateFlip method, but it only works with type Image. Basically, I want to rotate the image linked the file path instead of creating an image from that path, then rotating it. I would love some ideas. Thanks!
You can't rotate an image given it's path unless you load the image first.
By the way, there was no need to include information regarding the database you are using, that information has nothing to do with your problem.

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.

how to disable copying a picture from excel

I have sucessfully inserted image to excel sheet.Now i should not allow the picture to be copied by anyone. how can i achieve this?
any idea.
thanks in advance.
You can't.
Of course, there are certain measures you could employ, but there are always ways around them. You could (somehow) disable copy & paste within Excel, but then the user could take a screenshot (Alt-PrtScn) and crop it in an image editor.
If you somehow disable the ability to take a screenshot, they may feed the monitor output of their machine to another machine with a screen grabber, and get the image that way.
Or, of course, accepting the loss of quality, they could point a camera at their screen and get it that way.
If your excel file is accessible by anyone, then you can't.
You can only shrink the images to low resolution or putting watermark on it.
Depending on your environment and audience (eg, an internal document in your company), Office IRM can prevent the document from being copied and even copied using print-screen.
Personally, I see these attempts as naive at best - the data can be easily copied anyway (for example by taking a photo of the screen), but it sends the right message to your colleagues.

Categories