Skiasharp Export canvas to image [closed] - xamarin

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I have a question.
I have a skiasharp canvas with a few bitmaps. Now I want to export the canvas with the bitmaps to an Image, but I have no idea how to do that, or if that is possible.
Can someone help me?

You are probably looking to take a Snapshot of the Surface.
using (var image = surface.Snapshot())
using (var data = image.Encode(SKEncodedImageFormat.Png, 80))
using (var stream = File.OpenWrite(Path.Combine(FolderPath, "1.png")))
{
// save the data to a stream
data.SaveTo(stream);
}
This is very similar to MShah's answer, but just from a snapshot of the surface instead, given that surface is a reference to your Skia Surface.

To convert the bitmap to image:
using (var image = SKImage.FromBitmap(yourBitmap))
using (var data = image.Encode(SKEncodedImageFormat.Png, 80))
{
// save the data to a stream
using (var stream = File.OpenWrite(Path.Combine(FolderPath, "1.png")))
{
data.SaveTo(stream);
}
}
Edit:
To convert canvas to png:
SKImage mainCanvasImage = surface.Snapshot();
SKBitmap TempTIFbitmap1 = SKBitmap.Decode(mainCanvasImage.Encode())
Use the above code from point 1 to save this.
hope this will resolve your issue.

Related

Children elements didn't inherit parent data with D3 force layout [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have created a d3 force layout,and works very well.
My mainly code like so:
var nodes = [{id:1, n:'n_1',np:'0'},{id:2, n:'n_2',np:'0'}];//just for demo
//1. set data
var update = svg.selectAll(".node").data(nodes);
//2. enter
update.enter().append("svg:g").attr("class", "node")
.call(function(p){
p.append("svg:image").attr("class", "nodeimage");
p.append("svg:text").attr("class", "nodetext");
});
//3. exit
update.exit().remove();
As is known to us, d3.selectAll(".node").data() is my data. Because the child elements of g will inherit the data from the parent data, d3.selectAll(".nodeimage").data() is also my data.Am I right?
In fact, my data nodes is from backend, and the data is updated. For example, some properties like np have been changed from 0 to 1. We consider the result is
nodes = [{id:1, n:'n_1',np:'1'},{id:2, n:'n_2',np:'0'}];
I need to call the function above again. However,d3.selectAll(".node").data() is right, while d3.selectAll(".nodeimage").data() is wrong now.
The following code will not work well.
d3.selectAll('.nodeimage').attr("test", function(d){
//d.np is a wrong value.
});
Any suggestions for me?
Here is my demo of jsfiddle:http://jsfiddle.net/bpKG4/663/
This is a strange behavior of d3. If I understand correctly (which is not granted), selection.data(...) automatically transfers data to child elements, unless they already have some data binded.
In your case, it means that you need to copy "by hand" the data to each child:
//select any child node, then:
.each(function() {
d3.select(this).datum(d3.select(this.parentNode).datum());
})
NB: in your fiddle, you only set the xlink:href in the enter() selection: this is wrong, you need to set it within the whole update selection.
update.selectAll(".nodeimage")
.each(function() {
d3.select(this).datum(d3.select(this.parentNode).datum());
})
.attr("xlink:href", function(d){
var img;
if(d.np == 1){
img = "http://www.gravatar.com/avatar/1eccef322f0beef11e0e47ed7963189b/?default=&s=80"
}else{
img = "http://www.gravatar.com/avatar/a1338368fe0b4f3d301398a79c171987/?default=&s=80";
}
return img;
});
See here: http://jsfiddle.net/cs4xhs7s/1/

How to align value axis width? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
chart
I want to align value axis above chart and below chart.
How to set axis width?
The simplest way to go about it is to set minMarginLeft to the same number on both charts.
I.e.:
AmCharts.makeChart( "chart1", {
"type": "serial",
"minMarginLeft": 80,
// ...
} );
AmCharts.makeChart( "chart2", {
"type": "serial",
"minMarginLeft": 80,
// ...
} );

Finding longPress release Location [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I'm Using LongPress on control and drag different positions in views. I found out the starting position using UIGestureRecognizerStateBegan. how do i found out the UIGestureRecognizerStateChanged position?
if( UIGestureRecognizerStateChanged)
{
CGPoint center = snapshot.center;
center.y = location.y;
snapshot.center = center;
}
if (UIGestureRecognizerStateEnded)
{
location = [longPress locationInView:self.tableView];
}

How can I save a color as a PNG image with a specific hex code and dimensions? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'd like to create a PNG file from a specified hex code, width and height. The PNG file will simply comprise the solid color, with the specified dimensions.
Example inputs include #CCCCCC (hex), 500 (width), 300 (height).
That would yield a PNG file that's simply a gray (#CCCCCC) rectangle, with the dimensions of 500 x 300.
Bitmap b = new Bitmap(16, 16);
using (Graphics g = Graphics.FromImage(b))
g.Clear(Color.Yellow);
The Bitmap object can now be used for any purpose you want. If you want to assign it to say a PictureBox, you can use PictureBox.Image = b;. If you want to save this image to disk, you can use b.Save() function and pass it the file path.
If you have a color code, you can use ColorTranslator class to create a Color object from it. It supports HTML, OLE and Win32 color coding schemes. For example, you can use ColorTranslator.FromHtml("#286ECA") to return a Color object of the equivalent color.
You can use Graphics and Bitmap.
Bitmap bmp = new Bitmap(16, 16);
using (Graphics graphics = Graphics.FromImage(bmp))
{
using (SolidBrush brush = new SolidBrush(Color.Yellow))
{
graphics.FillRectangle(brush, 0, 0, bmp.Width, bmp.Height);
}
}
this.BackgroundImage = bmp;
Creating an image with a specified background color can be done like this:
create a Bitmap of the desired size
create a Graphics object that is using the newly created bitmap in order to draw on it
fill the bitmap with the desired color, for example using the Graphics.FillRectangle method
A possible solution could look like this:
var bitmap = new Bitmap(16, 16);
using (var g = Graphics.FromImage(bitmap))
{
g.FillRectangle(Brushes.Yellow, new Rectangle(0, 0, bitmap.Width, bitmap.Height));
}
bitmap.Save("d:\\yellow.jpg");
// or use the bitmap for further operations
If you want to set the colors from RGB values, then you can use the Color.FromArgb method:
var bitmap = new Bitmap(16, 16);
using (var g = Graphics.FromImage(bitmap))
{
using (var brush = new SolidBrush(Color.FromArgb(255, 255, 0)))
{
g.FillRectangle(brush, new Rectangle(0, 0, bitmap.Width, bitmap.Height));
}
}
bitmap.Save("d:\\yellow.jpg");
// or use the bitmap for further operations
As pointed out by #dotNet you can use the ColorTranslator.FromHtml method to parse the specified color:
var bitmap = new Bitmap(16, 16);
using (var g = Graphics.FromImage(bitmap))
{
var colorCode = "#286ECA";
var color = ColorTranslator.FromHtml(colorCode);
using (var brush = new SolidBrush(color))
{
g.FillRectangle(brush, new Rectangle(0, 0, bitmap.Width, bitmap.Height));
}
}
bitmap.Save("d:\\colors.jpg");
// or use the bitmap for further operations

Can give currency pattern in yaxis tickLabel in jqplot? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Here is my script
<script type="text/javascript">
function my_ext() {
this.cfg.axes.yaxis.tickOptions = {
formatString : ''
};
}
</script>
I want to format the numbers on my axis like this: 100,000,000.00. How do I do this in jqplot?
This is the formatting you need:
tickOptions:{formatString:"%'.2f"}
' for the english numeration
.2 is the number of digit after the point

Resources