Jump to content

Welcome! You're currently a Guest.

If you'd like to join in the Discussion, or access additional features in our forums, please sign in with your Evernote Account here. Have an Evernote Account but forgot your password? Reset it! Don't have an account yet? Create One! You'll need to set your Display Name before your first post.

Photo

windows phone 7 attaching an image g

wp7 en media ta attaching image

  • Please log in to reply
8 replies to this topic

#1 daemon salvatore

daemon salvatore

  • Pip
  • Title: Member
  • Group: Members
  • 3 posts

Posted 04 July 2012 - 01:21 AM

Hello fellow developers ,

i am developing a windows phone 7 app using evernote api using the sample code given in c# sdk for evernote

i want to attach a image in my note please help me i have tried following things (on the basis of php code mentioned on dev.evernote.com site) :--




//used dispatcher to convert image to byte array to avoid invaild thread access

UIThread.Invoke(() => test = new WriteableBitmap(myBitMapImage) );
UIThread.Invoke(() => byte[] arr = test.ToByteArray());

//to convert the image into hash i have done string hash = MD5CryptoServiceProvider.GetMd5String(myBitMapImage.ToString());

Data data = new Data();
data.Body = arr;
data.BodyHash = arr;




Resource io = new Resource();

io.Data = data;
io.Attributes.FileName = myBitMapImage.ToString();
string p="Image/jpeg";
List top = new List();
top.Add(io);
Note newNote = new Note
{
NotebookGuid = defaultNotebook.Guid,



Content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<!DOCTYPE en-note SYSTEM \"[url="http://xml.evernote.com/pub/enml2.dtd%5C"]http://xml.evernote.com/pub/enml2.dtd\[/url]">" +
"<en-note>my text " +
//if i add "<en-media type=image/jpeg hash="hash.tostring()" /> i get runtime error in Notestore.cs in " if (result.__isset.userException) {
//throw result.UserException;" please tell me its format for c# as in php its written as !! "<en-media type="image/jpeg" hash="' $hashHex'"/> " !! why this code snippet not give in c# ? plese help stuck here for many hrs now only error stopping me from futher //progress
"",
Title = "fuddu"
};

newNote.ContentHash = arr;


newNote.Resources = top;

Note createdNote = noteStore.createNote(authToken, newNote);

ShowMessage("Successfully created new note with GUID: " + createdNote.Guid);




please help me if you can as i am stuck here for very long and not much resources for wp7 on the internet.

PS: calling daminan sir and seth hitchlings for help .

best regards

daemon

#2 daemon salvatore

daemon salvatore

  • Pip
  • Title: Member
  • Group: Members
  • 3 posts

Posted 04 July 2012 - 09:59 AM

Calling SethH sir for help ... any mods please help me out on this topic .. please help me if u can

any help will be greatly appreciated please let me know haw to attach image in note in c#

best regards
daemon

#3 Julien Boedec

Julien Boedec

  • Title: Browncoat
  • Group: Evernote Employee
  • 407 posts

Posted 05 July 2012 - 05:04 PM

What exactly is happening? Does the image show up?

#4 daemon salvatore

daemon salvatore

  • Pip
  • Title: Member
  • Group: Members
  • 3 posts

Posted 06 July 2012 - 05:14 AM

nopes it gives runtime error in NoteStore.cs ... i just want a sample of creating a note with embedded media .. it is given in php and i am not able to convert it fully into c#

best regards
daemon

#5 Robby Gunawan

Robby Gunawan

  • Pip
  • Title: Member
  • Group: Members
  • 15 posts

Posted 10 December 2012 - 02:52 AM

I have same problem here, I don't know how to upload image from camera or screenshot to Evernote.
All examples are in php language, please create the C# version.

#6 Mustafa

Mustafa

  • Title: Shepherd
  • Group: Evernote Employee
  • 187 posts

Posted 10 December 2012 - 09:07 PM

There is a sample app in the C# SDK to create an image note : https://github.com/e...r/sample/client . Please try that. If this doesn't work for you, please send me a sample app that is not working for you at mustafa@evernote.com

#7 Robby Gunawan

Robby Gunawan

  • Pip
  • Title: Member
  • Group: Members
  • 15 posts

Posted 11 December 2012 - 08:09 AM

Found new "error", in WP7 is not supporting this byte[] hash = new MD5CryptoServiceProvider().ComputeHash(imagesBytes);

Do I have to use MD5?

#8 Robby Gunawan

Robby Gunawan

  • Pip
  • Title: Member
  • Group: Members
  • 15 posts

Posted 12 December 2012 - 02:34 AM

Update:
for My previous error, solved by using 3rd component, import new that component with

using JeffWilcox.Utilities.Silverlight;

you can download here : http://www.jeff.wilc...verlight-2-md5/


Got new error, I got
WP7 Invalid cross-thread access

at this command: WriteableBitmap wb = new WriteableBitmap(new BitmapImage(uri));

#9 Robby Gunawan

Robby Gunawan

  • Pip
  • Title: Member
  • Group: Members
  • 15 posts

Posted 17 December 2012 - 07:07 AM

I got the solution, here is the code
public void RunImpl(object state)
	 {
		 if (authToken == "your developer token")
		 {
			 ShowMessage("Please fill in your devleoper token in Sample.cs");
			 return;
		 }
		 // Instantiate the libraries to connect the service
		 TTransport userStoreTransport = new THttpClient(new Uri(UserStoreUrl));
		 TProtocol userStoreProtocol = new TBinaryProtocol(userStoreTransport);
		 UserStore.Client userStore = new UserStore.Client(userStoreProtocol);
		 // Check that the version is correct
		 //bool versionOK =
		 // userStore.checkVersion("Evernote EDAMTest (WP7)",
		 //	 Evernote.EDAM.UserStore.Constants.EDAM_VERSION_MAJOR,
		 //	 Evernote.EDAM.UserStore.Constants.EDAM_VERSION_MINOR);
		 //InvokeOnUIThread(() => ViewModel.TheViewModel.VersionOK = versionOK);
		 //Debug.WriteLine("Is my Evernote API version up to date? " + versionOK);
		 //if (!versionOK)
		 //{
		 // return;
		 //}
		 // Get the URL used to interact with the contents of the user's account
		 // When your application authenticates using OAuth, the NoteStore URL will
		 // be returned along with the auth token in the final OAuth request.
		 // In that case, you don't need to make this call.
		 String noteStoreUrl = userStore.getNoteStoreUrl(authToken);
		 TTransport noteStoreTransport = new THttpClient(new Uri(noteStoreUrl));
		 TProtocol noteStoreProtocol = new TBinaryProtocol(noteStoreTransport);
		 NoteStore.Client noteStore = new NoteStore.Client(noteStoreProtocol);
		 // Listing all the user's notebook
		 List<Notebook> notebooks = noteStore.listNotebooks(authToken);
		 // Debug.WriteLine("Found " + notebooks.Count + " notebooks:");
		 InvokeOnUIThread(() => notebooks.ForEach(notebook => ViewModel.TheViewModel.Notebooks.Add(notebook)));
		 // Find the default notebook
		 Notebook defaultNotebook = notebooks.Single(notebook => notebook.DefaultNotebook);
		 // Printing the names of the notebooks
		 //foreach (Notebook notebook in notebooks)
		 //{
		 // radListPicker1.Items.Add(notebook.Name);
			
		 //}
		 // Listing the first 10 notes in the default notebook
		 NoteFilter filter = new NoteFilter { NotebookGuid = defaultNotebook.Guid };
		
		 NoteList notes = noteStore.findNotes(authToken, filter, 0, 10);
		 InvokeOnUIThread(() => notes.Notes.ForEach(note1 => ViewModel.TheViewModel.Notes.Add(note1)));
		 foreach (Note note1 in notes.Notes)
		 {
			 Debug.WriteLine(" * " + note1.Title);
		 }

		 Note mynote1 = new Note();

		 // Uri uri = null;

		 // uri = new Uri(String.Format("/DiaryKuliner;component/Images/makanan.jpg"), UriKind.Relative);

		 MemoryStream ms = new MemoryStream();
		 MemoryStream ms1 = new MemoryStream();
		 byte[] imagesBytes;
		 byte[] hash;
		 byte[] imagesBytes1;
		 byte[] hash1;

		 Deployment.Current.Dispatcher.BeginInvoke(() =>
{

     wb = new WriteableBitmap(450, 344);
	 wb.Render(map1, new MatrixTransform());
	 wb.Invalidate();

	 wb1 = new WriteableBitmap(450, 344);
	 wb1.Render(image, new MatrixTransform());
	 wb1.Invalidate();

});

		 Thread.Sleep(500);

		 wb.SaveJpeg(ms, wb.PixelWidth, wb.PixelHeight, 0, 100);
		 wb1.SaveJpeg(ms1, wb1.PixelWidth, wb1.PixelHeight, 0, 100); //untuk hasil dari camera
		 imagesBytes = ms.ToArray();
		 imagesBytes1 = ms1.ToArray();

		 hash = new MD5CryptoServiceProvider().ComputeHash(imagesBytes);
		 hash1 = new MD5CryptoServiceProvider().ComputeHash(imagesBytes1);
		 Data data = new Data();
		 data.Size = imagesBytes.Length;
		 data.BodyHash = hash;
		 data.Body = imagesBytes;
		 Data data1 = new Data();
		 data1.Size = imagesBytes1.Length;
		 data1.Body = hash1;
		 data1.Body = imagesBytes1;

		 Resource resource = new Resource();
		 resource.Mime = "image/jpeg";
		 resource.Data = data;
		 Resource resource1 = new Resource();
		 resource1.Mime = "image/jpeg";
		 resource1.Data = data1;

		 mynote1.Resources = new List<Resource>();
		 mynote1.Resources.Add(resource);
		 mynote1.Resources.Add(resource1);

		 // To display the Resource as part of the note1's content, include an <en-media>
		 // tag in the note1's ENML content. The en-media tag identifies the corresponding
		 // Resource using the MD5 hash.
		 string hashHex = BitConverter.ToString(hash).Replace("-", "").ToLower();
		 string hashHex1 = BitConverter.ToString(hash1).Replace("-", "").ToLower();
		 // The content of an Evernote note1 is represented using Evernote Markup Language
		 // (ENML). The full ENML specification can be found in the Evernote API Overview
		 // at http://dev.evernote.com/documentation/cloud/chapters/ENML.php

		 mynote1.Title = curTitle;
		 mynote1.Content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
					 "<!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\">" +
					 "<en-note>" + curContent + "<br/>" +
					 "Lokasi : <br/> <en-media type=\"image/png\" hash=\"" + hashHex + "\"/>" + "<br/>" +
					 "Gambarnya :<br/> <en-media type=\"image/png\" hash=\"" + hashHex1 + "\"/>" + "<br/>" +
					 "<br/><br/><br/><br/> © DiaryKuliner 2012 -- Syncs with Evernote®" +
					 "</en-note>";
		 // Finally, send the new note1 to Evernote using the createNote method
		 // The new Note object that is returned will contain server-generated
		 // attributes such as the new note1's unique GUID.
		 Note createdNote1 = noteStore.createNote(authToken, mynote1);
		 //Note ambilNote = noteStore.getNote(authToken, createdNote1.Guid, true, true, true, true);
		
		 ShowMessage("Successfully created new note1 with Title : " + createdNote1.Title);
		 Deployment.Current.Dispatcher.BeginInvoke(() =>
		 {
			 txtContent.Text = "";
			 txtTitle.Text = "";
			 mypivot.SelectedIndex = 0;
		 });
		
	 }

The explanation is, this code
         Deployment.Current.Dispatcher.BeginInvoke(() =>
{

     wb = new WriteableBitmap(450, 344);
	 wb.Render(map1, new MatrixTransform());
	 wb.Invalidate();

	 wb1 = new WriteableBitmap(450, 344);
	 wb1.Render(image, new MatrixTransform());
	 wb1.Invalidate();

});
is use to generate writeable bitmap "in background", if don't use Deployment.Current.Dispatcher.BeginInvoke(( will raise an error, after create writeablebitmap, add Resouces and attach, almost the same with Evernote C# Client (windows form) sample.

Hope my explanation clear.. if need help, please send mail to rgunawans@gmail.com,





Also tagged with one or more of these keywords: wp7, en media ta, attaching image

1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users

Clip to Evernote