Techbirds | Knowledge Hub | Page 24

Hii all, To save canvas or children’s of canvas as an image use the following code under the click event of your save button here “mycanvas” is your canvas name which is to be saved as an image.

try { int height = Convert.ToInt32(Application.Current.RootVisual.RenderSize.Height); int width = Convert.ToInt32(Application.Current.RootVisual.RenderSize.Width); var bitmap = new WriteableBitmap(height, width); bitmap.Render(mycanvas, null); //Renders an element within the bitmap bitmap.Invalidate(); // Request a draw or redraw of the entire bitmap var fileStream = new MemoryStream(); bitmap.SaveJpeg(fileStream, bitmap.PixelWidth, bitmap.PixelHeight, 0, 20); // Encode a WriteableBitmap object into a JPEG stream fileStream.Seek(0, SeekOrigin.Begin); MediaLibrary library = new MediaLibrary(); string imagename = “Image_Name”; // objMemory = fileStream; var pic = library.SavePicture(imagename, fileStream); MessageBox.Show(“Image saved”); } catch (Exception ex) { MessageBox.Show(ex.Message); }

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

try

                    {

                        int height = Convert.ToInt32(Application.Current.RootVisual.RenderSize.Height);

                        int width = Convert.ToInt32(Application.Current.RootVisual.RenderSize.Width);

                        var bitmap = new WriteableBitmap(height, width);

                        bitmap.Render(mycanvas, null); //Renders an element within the bitmap

                        bitmap.Invalidate();   // Request a draw or redraw of the entire bitmap

                        var fileStream = new MemoryStream();

                        bitmap.SaveJpeg(fileStream, bitmap.PixelWidth, bitmap.PixelHeight, 0, 20);  // Encode a WriteableBitmap object into a JPEG stream

                        fileStream.Seek(0, SeekOrigin.Begin);

                        MediaLibrary library = new MediaLibrary();

                        string imagename = “Image_Name”;

                        //    objMemory = fileStream;

                        var pic = library.SavePicture(imagename, fileStream);

                        MessageBox.Show(“Image saved”);

                    }

                    catch (Exception ex)

                    {

                        MessageBox.Show(ex.Message);

                    }

Canvas including its children’s is saved as an image. 1,122 total views, no views today

1,122 total views, no views today

Posted on: May 12, 2014 /

Categories: PHP / Author Name: Shivek Parmar

What is WordPress Heartbeat API : It allows WordPress to communicate between the web-browser and the server. It allows for improved user session management, revision tracking, and auto saving. The WordPress Heartbeat API uses /wp-admin/admin-ajax.php to run AJAX calls from the web-browser. Which in theory sounds awesome, as WordPress can keep track of what’s going on in the dashboard.

Read More →

1,725 total views, no views today

I am posting this blog because I have faced an issue to design input type file button. Default browse button doesn’t look so good but we can customize it. We can do this through javascript. ->First , hide the input type file button. ->Create your custom button. ->onclick Event of custom button call “javascript:document.getElementById(‘id_of_input_type_file_button’).click(); ->Therefore,

Read More →

853 total views, no views today

Hi all, In this post I will discuss how we can use TreeMap. Map is one of the important part of collection framework in Java. TreeMap is direct Concrete Class that implements Map Interface. A normal TreeMap with specified key and value pair.

import java.util.Collection; import java.util.TreeMap; import java.util.Iterator; public class TreeMapIterator { public static void main(String[] args) { // Create a TreeMap and populate it with elements TreeMap treeMap = new TreeMap(); treeMap.put(“key_1″,”element_1”); treeMap.put(“key_2″,”element_2”); treeMap.put(“key_3″,”element_3”); // Get a set of all the entries (key – value pairs) contained in the TreeMap Collection entrySet = treeMap.entrySet(); // Obtain an Iterator for the entries Set Iterator it = entrySet.iterator(); // Iterate through TreeMap entries System.out.println(“TreeMap entries : “); while(it.hasNext()) System.out.println(it.next()); } }

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

import java.util.Collection;

import java.util.TreeMap;

import java.util.Iterator;

public class TreeMapIterator {

public static void main(String[] args) {

  // Create a TreeMap and populate it with elements

  TreeMap treeMap = new TreeMap();

  treeMap.put(“key_1″,”element_1”);

  treeMap.put(“key_2″,”element_2”);

  treeMap.put(“key_3″,”element_3”);

  // Get a set of all the entries (key – value pairs) contained in the TreeMap

  Collection entrySet = treeMap.entrySet();

  // Obtain an Iterator for the entries Set

  Iterator it = entrySet.iterator();

  // Iterate through TreeMap entries

  System.out.println(“TreeMap entries : “);

  while(it.hasNext())

    System.out.println(it.next());

    }

}

  553 total views, no views today

553 total views, no views today

//Canvas drawing and little animation : Beginning Tutorial : By Tapan saini For any amination task one can either use openGL and openCV… but doing painting on your own will keep you focused on learning . Reusability is good but i believe not to depend on resources too much. How to DO drawing on Canvas.

Read More →

572 total views, no views today