|
when I have a BitmapSource I can easily
BitmapSource img = ...;
using (var stream = new FileStream("scene.png", FileMode.Create))
{
var encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(img));
encoder.Save(stream);
}
Unfortunately D3DImage is not a BitmapSource !
So.. how could I save my D3DImage to a PNG file?
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
modified on Monday, May 2, 2011 1:37 PM
|
|
|
|
|
I'm using SharpDX[^] so I have a fully managed DirectX environment.
I figured it out!
Just for the info, here is how!
class Program
{
unsafe static void Main(string[] args)
{
using (var d3d2d = new D3D11_2D1())
{
d3d2d.Reset(250, 250);
var sc = new Scene_11() { Context = d3d2d.Drawing };
var scw = new SceneDwrite() { Context = d3d2d.Text };
var rargs = new RenderArgs();
d3d2d.BeginRender(rargs);
sc.Render(rargs);
scw.Render(rargs);
d3d2d.EndRender(rargs);
Save1(d3d2d);
}
}
unsafe private static void Save1(D3D11_2D1 d3d2d)
{
var wb = GetBitmap(d3d2d.Drawing.BackBuffer);
using (var stream = new FileStream("scene.png", FileMode.Create))
{
var encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(wb));
encoder.Save(stream);
}
}
unsafe private static void Save2(D3D11_2D1 d3d2d)
{
using (var teximg = GetCopy(d3d2d.Drawing.BackBuffer))
Resource.ToFile(teximg.Device.ImmediateContext, teximg, ImageFileFormat.Png, "scene.png");
}
unsafe private static WriteableBitmap GetBitmap(Texture2D tex)
{
int w = tex.Description.Width;
int h = tex.Description.Height;
var wb = new WriteableBitmap(w, h, 96.0, 96.0, PixelFormats.Bgra32, null);
wb.Lock();
uint* wbb = (uint*)wb.BackBuffer;
var db = GetDataBox(tex);
db.Data.Position = 0;
for (int y = 0; y < h; y++)
{
db.Data.Position = y * db.RowPitch;
for (int x = 0; x < w; x++)
{
var c = db.Data.Read<uint>();
wbb[y * w + x] = c;
}
}
wb.AddDirtyRect(new Int32Rect(0, 0, w, h));
wb.Unlock();
return wb;
}
private static DataBox GetDataBox(Texture2D tex)
{
var db = GetDataBox(tex, 1);
return GetDataBox(tex, tex.Description.Height * db.RowPitch);
}
private static DataBox GetDataBox(Texture2D tex, int size)
{
using (var teximg = GetCopy(tex))
return tex.Device.ImmediateContext.MapSubresource(
teximg
, 0
, size
, MapMode.Read
, MapFlags.None);
}
private static Texture2D GetCopy(Texture2D tex)
{
var textimgdesc = tex.Description;
textimgdesc.SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0);
textimgdesc.Usage = ResourceUsage.Staging;
textimgdesc.BindFlags = BindFlags.None;
textimgdesc.CpuAccessFlags = CpuAccessFlags.Read | CpuAccessFlags.Write;
var teximg = new Texture2D(tex.Device, textimgdesc);
tex.Device.ImmediateContext.CopyResource(tex, teximg);
return teximg;
}
}
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
Hi Experts ,
Could you help me in using safeHandle instead of IntPtr.I am trying to fix CA2006 reliability warning, but MSDN is lacking of examples.
|
|
|
|
|
SafeHandle[^]
I know nothing , I know nothing ...
RIP Osama Bin Laden, you were thorn in USA throat ,
And you will always be ...
|
|
|
|
|
Bonjour,
je voudrai savoir comment enregistrer un chemin de fichier pdf dans la base de données.j'ai déja fait un code d' enregistrer mais au moment ou je clique sur le bouton "enregistrer, tous les autres champs s'ajoutent dans la base de données sql server 2008 sauf le chemin qui ne s'ajoute pas,son champs reste vide .voilà mon code du bouton enregistrer
try
{//je clique sur le bouton parcourir qui me permet de choisir le pdf à choisir et après son chemin s'affiche dans listbox
if (listBox1.Text == "" || txtLibellé.Text == "" || cbtheme.Text == "")
MessageBox.Show("remplisser d'abord les zones vides!!");
else if (o.Verifier(" Document ", " chemin ", listBox1.Text) == true)
{
MessageBox.Show("existe deja");
}
else
{
o.exec("Insert into Document Values ('" + listBox1.Text + "','" + txtLibellé.Text + "','" + dateTimePicker1.Text + "','" + cbtheme.Text + "')", false);
MessageBox.Show(" c'est enregistré!!!");
Liste();
o.ligne = o.dt.Rows.Count - 1;
}
}
catch (Exception Ex)
{
MessageBox.Show("" + Ex);
}
|
|
|
|
|
هذا الموقع بل الإنجليزية
Perhaps now you understand the importance of keeping the website in one Language, in our case English. This isn't the UN after all.
While we are at at it:
Marking something as urgent is rude (Read the FAQs) - it might be to you, it isn't to us, and we are unpaid.
You have not formatted the code so we can't read it (See the FAQs)
|
|
|
|
|
|
I have no idea what you said, but you need to read up on SQL injection attacks.
|
|
|
|
|
|
immer ist alles dringend!
I cannot remember: What did I before google?
|
|
|
|
|
Thomas Krojer wrote: immer ist alles dringend!(everything is always urgent)
You are right. And CP becomes their emergency room.
Ignorance of the ability brings disability.
|
|
|
|
|
hi.
i need codes in c# for recording video with webcam.
this program have 3 buttons
1.turn on webcam
2.record
3.save the recordes
|
|
|
|
|
A little effort via Google and you will find them. You may also like to check this[^] out, especially point 2.
The best things in life are not things.
|
|
|
|
|
naalgo wrote: i need codes in c# for recording video with webcam.
I'll build it for $5000.
I are Troll
|
|
|
|
|
I'll build it for $4999, but I won't do as good a job as Eddy
|
|
|
|
|
5000? 11900! You offerd it to cheap!!
I cannot remember: What did I before google?
|
|
|
|
|
Thomas Krojer wrote: 5000? 11900! You offerd it to cheap!!
I tried to undercut all other offerings, but as you can see it didn't work
I are Troll
|
|
|
|
|
Here are some codes you may find useful:
using System;
using System.Collections.Generic;
The rest I leave as an assignment for you.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
|
You could always buy a webcam, install the software that goes with it, finds the appropriate dll's, reverse engineer them, re-format them to your coding standards, framework and language and then compile.
V.
|
|
|
|
|
Somewhere, a polar bear just died because you wasted electricity typing that.
|
|
|
|
|
Hello Everybody,
I have a component which is not serialize and now i am trying to save it in file with the use of binary serialization.
But it's not saving yet. And shows the message your component is not serialize.
So please help me to serialize this object.
If you can think then I Can.
|
|
|
|
|
It's all explained here[^] in this CodeProject article.
The best things in life are not things.
|
|
|
|
|
Short answer: put [Serializable] on the component and make sure that all its fields are themselves serialisable.
|
|
|
|
|
Dear Sir,
Thanks for reply. But this component is not develop by me. this is third party control.
So how can i do that?
Thanks Again
If you can think then I Can.
|
|
|
|