以下の2つのコードニッペットを持つ座標系によって作成されます。残念ながら、2番目のコードスニペットは、イメージをデスクトップに保存します。私は "イメージ"を返すようにしたいと思います。座標系のイメージを返すにはどうすればよいですか? (Iピクチャとして戻り値を持つメソッドを持っている)画像を返却するにはどうすればよいですか?
終わりには、デスクトップへの座標系から、「画像」とはないが保存されているようpreview = image;
なければならないが、私ができますそれを返す。
var stream = new MemoryStream();
var pngExporter = new PngExporter { Width = 600, Height = 400, Background = OxyColors.White };
pngExporter.Export(plotModel, stream);
preview = stream; //Does not work unfortunately
var pngExporter = new PngExporter { Width = 350, Height = 350, Background = OxyColors.White };
pngExporter.ExportToFile(plotModel, @"C:\Users\user\Desktop\test.png");
public bool createPreview(out string errorMessage, out System.Drawing.Image preview, int pWidth, int pHeight, int pMargin)
{
errorMessage = null;
preview = null;
bool folded = false;
try
{
PlotModel plotModel = new PlotModel { Title = "Vorschaukomponente" };
plotModel.Axes.Add(new OxyPlot.Axes.LinearAxis { Position = OxyPlot.Axes.AxisPosition.Bottom, MinimumPadding = 0.1, MaximumPadding = 0.1 });
plotModel.Axes.Add(new OxyPlot.Axes.LinearAxis { Position = OxyPlot.Axes.AxisPosition.Left, MinimumPadding = 0.1, MaximumPadding = 0.1 });
var series1 = new OxyPlot.Series.LineSeries
{
LineStyle = LineStyle.None,
MarkerType = MarkerType.Circle,
MarkerSize = 2,
MarkerFill = OxyColors.Transparent,
MarkerStroke = OxyColors.Black,
MarkerStrokeThickness = 1
};
if (pointX.Count == pointY.Count)
{
for (int i = 0; i < pointX.Count; i++)
{
for (int g = i; g < pointY.Count; g++)
{
series1.Points.Add(new DataPoint(pointX[i], pointY[g]));
Console.WriteLine(i+1 + " | "+ pointX[i].ToString() + "/" + pointY[g]);
break;
}
}
series1.Smooth = true;
plotModel.Series.Add(series1);
try
{
var stream = new MemoryStream();
var pngExporter = new PngExporter { Width = 600, Height = 400, Background = OxyColors.White };
pngExporter.Export(plotModel, stream);
preview = stream;
// var pngExporter = new PngExporter { Width = 350, Height = 350, Background = OxyColors.White };
// pngExporter.ExportToFile(plotModel, @"C:\Users\user\Desktop\test.png");
folded = true;
}
catch (Exception exc)
{
System.Diagnostics.Debug.WriteLine(exc.Message);
errorMessage = "Es konnt kein Bild erstellt werden.";
folded = false;
}
}
else
{
errorMessage = "Es ist nicht die gleiche Anzahl von xen und yen vorhanden.";
folded = false;
}
}
catch (Exception)
{
errorMessage= "Es trat ein unerwarteter Fehler auf";
folded = false;
}
return folded;
}
を助けている場合、私に教えてください。 BitmapEncoderエンコーダ=新しいPngBitmapEncoder(); Encoder.Frames.Add(BitmapFrame.Create(sa)); Encoder.Save(fileStream); ' MainWindowには何が問題なのですか? – GabelUndMesser
これはまったく異なる質問です。回答する情報が少なすぎる場合は、新しい質問をしてください。 – jeroenh
残念ながら、ソリューションのアプローチをテストすることはできませんが、その後は新しい質問をします。お返事をありがとうございます。 – GabelUndMesser