Silverlight deep zoom composing issue - c#

Deep zoom composer itself is very nice tool. I am wondering if there are any automatic ways to compose? For example, I have 100 images, and I want to compose automatically as 10 * 10 deep zoom effect. I am implementing a background workflow and automatically composing deep zoom and publish. The Output Type I prefer is "Images" and "Export as a collection (multiple images)".
Any reference samples or documents? I am using VSTS2008 + C# + .Net 3.5.

Take a look at this post about DeepZoomTools.dll included in the app.

There's a great sample project here and if you really want to go crazy and generate images/tiles programatically, you can try the sort of thing referenced in this MSDN article.
I haven't found a lot of real documentation regarding DeepZoomTools.dll myself, but I created a small test webservice to turn a single uploaded image into a Deep Zoom source. The relevant code is:
public string CreateDeepZoomImage(byte[] abyte, string fileName)
{
ImageCreator ic = new ImageCreator();
string FilePath = Path.Combine(_uploadPath, fileName);
System.IO.FileStream fs = new System.IO.FileStream(FilePath, System.IO.FileMode.Create);
fs.Write(abyte, 0, abyte.Length);
fs.Close();
FileInfo imageFileInfo = new FileInfo(FilePath);
string destination = imageFileInfo.DirectoryName + "\\" + imageFileInfo.Name.TrimEnd(imageFileInfo.Extension.ToCharArray()) + "\\output.xml";
ic.Create(FilePath, destination);
string returnpath = "/Uploads/" + imageFileInfo.Name.TrimEnd(imageFileInfo.Extension.ToCharArray()) + "/output.xml";
return returnpath;
}
Where the return path is used like so:
ZoomImage.Source = new DeepZoomImageTileSource(new Uri(e.Result, UriKind.Relative));
(Forgive the sloppy code. It does work though.)

Related

Application not saving png file on phone - unity

I am making a camera app on unity for learning purpose. I followed two tutorial and got my cam running Now here is a code that I found on stack overflow, The issue is its not saving the output on phone.
public void Pic()
{
StartCoroutine(TakePhoto());
}
IEnumerator TakePhoto() // Start this Coroutine on some button click
{
// NOTE - you almost certainly have to do this here:
yield return new WaitForEndOfFrame();
Texture2D photo = new Texture2D(backCam.width, backCam.height);
photo.SetPixels(backCam.GetPixels());
photo.Apply();
//Encode to a PNG
byte[] bytes = photo.EncodeToPNG();
//Write out the PNG. Of course you have to substitute your_path for something sensible
File.WriteAllBytes(Application.dataPath + "photo.png", bytes);
}
I have attached Pic() to a button.
I am just learning these so might be making some stupid mistake.
It needs to be /photo.png, otherwise you are just appending a filename to foldername
You should also consider switching to persistentDataPath and validating it for file io (checking if it exists is a good practice)
For Paths you should always use Path.Combine instead of direct string concatenation
Path.Combine(Application.dataPath, "photo.png")
It is also possible that the folder or file simply don't exist yet so you could check that and create them in that case before writing
var filePath = Path.Combine(Application.dataPath, "photo.png");
if (!Directory.Exists(Application.dataPath))
{
Directory.CreateDirectory(Application.dataPath);
}
if (!File.Exists(filePath))
{
File.Create(filePath);
}
//Write out the PNG. Of course you have to substitute your_path for something sensible
File.WriteAllBytes(filePath, bytes);
You need to add a slash before your file name.
File.WriteAllBytes($"{Application.dataPath}/photo.png", bytes);

How to figure out direction of text or page with tesseract

So I have been trying to figure this out for a whole day now. And I really hope someone will be able to help me out.
I am trying to write a software, that will process a PDF document. Processing means, deleting empty pages and rotating pages that have been scanned upside down.
Obviously I need some kind of OCR library here, so I went with Tesseract. Detecting empty pages was easy enough. But the Orientation property doesn't seem to work at all (EDIT: by not working I mean it always says "PageUp"). But from what I gathered so far, this should give me a hint to whether or not my page is upside down. Am I missing something? Maybe something that has to be included in the tessdata folder for this?
I also tried the approach of testing for GetMeanConfidence, flip the image and then compare the MeanConfidences, because in theory the page that wasn't upside down, should be easier to read. But the difference is so minimal, that I don't think this is reliable.
And I switched the language attribute of the TesseractEngine. I tried "eng", "deu", and "osd". All with the same result.
Bitmap image = new Bitmap(filepath);
var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase);
path = Path.Combine(path, "tessdata");
path = path.Replace("file:\\", "");
var engine = new TesseractEngine(path, "osd", EngineMode.TesseractOnly);
using (var img = PixConverter.ToPix(image))
{
using (var page = engine.Process(img, PageSegMode.AutoOsd))
{
var pageIterator = page.AnalyseLayout();
pageIterator.Begin();
var pageProperties = pageIterator.GetProperties();
Console.WriteLine(pageProperties.Orientation.ToString() +" "+
pageProperties.TextLineOrder + " " + pageProperties.DeskewAngle + " " +
pageProperties.WritingDirection);
Console.WriteLine(page.GetMeanConfidence());
}
}
I expect an output that tells me if the page is upside down. So that I know if it has to be rotated or not. Performance doesn't matter!
I am also open for different approaches and libraries (as long as they're free).

How to generate .pkpass files in C# to add to my e-wallet?

I have an app written in C# that generates cards (similar to our personal id). Now, i wanted to add that card to an e-wallet. I searched through the web and found that to do that i needed to create a .pkpass file and then i could upload this file to my e-wallet. First of all, is this the only way to add my card to my e-wallet?
Also, i understood that i needed certificates. I took a peek at Passbook Generator and it is said that i need a full Apple developer account (which i don't have) to download one of the certificates. So, i'm struggling a bit to understand what i really need to accomplish what i want.
Thank you in advance for your help.
Rafael Valente
the following worked for me
DirectoryInfo location = new DirectoryInfo(SourceLocation);
byte[] bytes = System.IO.File.ReadAllBytes(location.FullName);
XmlDocument PkPassFile = new XmlDocument();
MemoryStream memstream = new MemoryStream(bytes);
PkPassFile.Load(memstream);
string FullFileName = DestinationFolder+ #"\" + file.Name + ".pkpass";
rdlFile.Save(FullFileName);
basically you read the file into a byte[],
take that and paste it into memorystream,
add that to a xmldocument and save the conent of the xmlfile as a .pkpass file
RESULT

XSL + XML -> PDF for C#

I know several people asked questions like this, but no answer helped to solve my problem.
Well, I have xsl and xml and want to generate pdf with a processor like Apache.FOP.
I am not able to use any JAVA programms like that. Just able to use C# libraries / exe.
I tried to use nFop:
Version 1.x uses Java.io and..
Version 2.0 doesn't have the ability to set XsltSettings
My current Software uses XSL + XML -> HTML (using standard Stystm.Xml.Xsl on C#) and wktmltopdf to generate PDF from created HTML.
But tables got split when they are too long for the page, and on the next page you don't have any column headers (this is very important for my problem).
I think there are no Free FO-Processor for pure C
Have a look at FoNET.
public static bool XMLToPDF(string pXmlFile, string pXslFile, string pFoFile, string pPdfFile)
{
string lBaseDir = System.IO.Path.GetDirectoryName(pXslFile);
XslCompiledTransform lXslt = new XslCompiledTransform();
lXslt.Load(pXslFile);
lXslt.Transform(pXmlFile, pFoFile);
FileStream lFileInputStreamFo = new FileStream(pFoFile, FileMode.Open);
FileStream lFileOutputStreamPDF = new FileStream(pPdfFile, FileMode.Create);
FonetDriver lDriver = FonetDriver.Make();
lDriver.BaseDirectory = new DirectoryInfo(lBaseDir);
lDriver.CloseOnExit = true;
lDriver.Render(lFileInputStreamFo, lFileOutputStreamPDF);
lFileInputStreamFo.Close();
lFileOutputStreamPDF.Close();
return System.IO.File.Exists(pPdfFile);
}

Sitecore media library paths

Using Sitecore 6.5, when images are rendered on a web page, a URL such as the one below is used
~/media/OSS/Images/MyImage
But if you add an image from the library in a content editor a path such as below is used
~/media/1CFDDC34C94E460FAA2B1518DCA22360.PNG
This makes sense as it's trying to use a meaningful path when rendered for the web.
We would like to use the first media image path to add images in the content editor in HTML view rather than the default second method. This is because we are actually taking some html files and automatically adding them in to Sitecore via a script and we can change the image paths to a location in the media library if the first image format is used by using a convention so the images should appear in the newly created items. We have now idea about a media library image ID.
The first format does appear to work as images are rendered in the content editor design editor and when the page is rendered but Sitecore marks these as broken links in the Content Editor. Are any ideas on whether we are safe to use this format?
You may want to avoid hard coding paths to media in the rich text field. The second "dynamic link" is an important feature of Sitecore in that it keeps a connection between the media and item in the Links database. This safeguards you if you ever delete or move the media.
Since it sounds like you are importing content from an external source and you already have a means of detecting the image paths, I would recommend (if possible) that you upload the images programmatically and insert the dynamic links.
Below is a function that you can call for uploading to the Media Library and getting back the media item:
Example usage:
var file = AddFile("/assets/images/my-image.jpg", "/sitecore/media library/images/example", "my-image");
The code:
private MediaItem AddFile(string relativeUrl, string sitecorePath, string mediaItemName)
{
var extension = Path.GetExtension(relativeUrl);
var localFilename = #"c:\temp\" + mediaItemName + extension;
using (var client = new WebClient())
{
client.DownloadFile("http://yourdomain.com" + relativeUrl, localFilename);
}
// Create the options
var options = new MediaCreatorOptions
{
FileBased = false,
IncludeExtensionInItemName = false,
KeepExisting = false,
Versioned = false,
Destination = sitecorePath + "/" + mediaItemName,
Database = Factory.GetDatabase("master")
};
// Now create the file
var creator = new MediaCreator();
var mediaItem = creator.CreateFromFile(localFilename, options);
return mediaItem;
}
As for generating the dynamic link to the media, I actually haven't found a Sitecore method to do this, so I resorted to the following code:
var extension = !String.IsNullOrEmpty(Settings.Media.RequestExtension)
? Settings.Media.RequestExtension
: ((MediaItem)item).Extension;
var dynamicMediaUrl = String.Format(
"{0}{1}.{2}",
MediaManager.MediaLinkPrefix,
item.ID.ToShortID(),
extension);
No it will not cause any rendering issue apart from the broken links notification as you noted. Also when you select an image in the editor and select to edit the media folder will be at the root rather than at the image itself. But as Derek has noted, the use of dynamic links is an important feature to make sure your links do not break if something is moved or deleted.
I would add to his answer that since you are adding the text via a script you can detect images in the text using HtmlAgilityPack (already used in Sitecore) or FizzlerEx (more similar to jQuery syntax), use the code he provided to upload the images to the media library, grab the GUID and replace the src. Something along the lines of:
string content = "<whatever your html to go in the rich text field>";
HtmlDocument doc = new HtmlDocument();
doc.Load(content);
foreach(HtmlNode img in doc.DocumentElement.SelectNodes("//img[starts-with(#src, '/media/')]")
{
HtmlAttribute attr = img["src"];
Item scMediaItem = UploadLocalMedia(attr.Value);
attr.Value = GetDynamicMediaUrl(scMediaItem);
}

Categories

Resources