Laden...

Forenbeiträge von DSS Ingesamt 11 Beiträge

26.09.2021 - 02:17 Uhr

Das Beispiel von Roseattacode hat leider kein C#-Beispiel.
Nach meiner Vermutung muss ich was mit der Funktion BitmapData was anstellen, diese Methode wurde schon angesprochen, nur wie sieht es nun wirklich aus?

DSS

25.09.2021 - 01:36 Uhr

Hallo
Wie erstelle ich in C# ein graphisches Plasma?
Habe folgenden Code, welcher aber nur ein Standbild erzeugt.
Für ein Beispiel oder einen Link wäre ich dankbar.

DSS


                Bitmap bm = new Bitmap(pictureBoxMain.Image);
                Bitmap newBitmap = new Bitmap(bm.Width, bm.Height);

                for (int y = 0; y < newBitmap.Height; y++)
                {
                    for (int x = 0; x < newBitmap.Width; x++)
                    {
                        int color = (int)(128.0 + (128.0 * Math.Sin((x) / 8.0)));
                        newBitmap.SetPixel(x, y, Color.FromArgb(color, color, color));
                    }
                }
                pictureBoxMain.Image = newBitmap;

10.06.2019 - 15:47 Uhr

Bei der Ausführung dieses Beispiel, fehlt mir das passende Bitmap. http://www.riemers.net/eng/Tutorials/DirectX/Csharp/Series1/tut10.php
Welches Format muss das Bitmap haben, ich selbst habe ein 64x64 Pixel Bitmap erstellt und dies mit der Software geladen. Nun ergibt sich ein > Fehlermeldung:

Über das Ende des Streams hinaus kann nicht gelesen werden .
Der Fehler befindet sich im "LoadHeightData"
Wie gross muss das Bitmap sein? Oder doch was im Code falsch?
Vielen Dank für die Hilfe.

Der Code:


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
using System.IO;
using Microsoft.DirectX.DirectInput;

namespace TestDirectXTerrain3
{
    public partial class Form1 : Form
    {
        private int WIDTH = 64;
        private int HEIGHT = 64;
        private Microsoft.DirectX.Direct3D.Device device;
        //private System.ComponentModel.Container components = null;        
        private float angle = 0f;
        private CustomVertex.PositionColored[] vertices;
        private int[,] heightData;
        private int[] indices;
        private IndexBuffer ib;
        private VertexBuffer vb;

        private Microsoft.DirectX.DirectInput.Device keyb;

        public Form1()
        {
            InitializeComponent();
            InitializeComponent();
            LoadHeightData();
            InitializeDevice();
            CameraPositioning();
            VertexDeclaration();
            IndicesDeclaration();
            InitializeKeyboard();

            this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true);
        }

        public void InitializeDevice()
        {
            PresentParameters presentParams = new PresentParameters();
            presentParams.Windowed = true;
            presentParams.SwapEffect = SwapEffect.Discard;
            device = new Microsoft.DirectX.Direct3D.Device(0, Microsoft.DirectX.Direct3D.DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, presentParams);
            device.RenderState.FillMode = FillMode.WireFrame;
            device.RenderState.CullMode = Cull.None;
        }

        private void CameraPositioning()
        {
            device.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4, this.Width / this.Height, 1f, 150f);
            device.Transform.View = Matrix.LookAtLH(new Vector3(0, -40, 50), new Vector3(0, -5, 0), new Vector3(0, 1, 0));

            //device.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4, this.Width / this.Height, 1f, 50f);
            //device.Transform.View = Matrix.LookAtLH(new Vector3(0, 0, 15), new Vector3(0, 0, 0), new Vector3(0, 1, 0));
            device.RenderState.Lighting = false;
            device.RenderState.CullMode = Cull.None;
        }

        private void VertexDeclaration()
        {
            vb = new VertexBuffer(typeof(CustomVertex.PositionColored), WIDTH * HEIGHT, device, Usage.Dynamic | Usage.WriteOnly, CustomVertex.PositionColored.Format, Pool.Default);
            vertices = new CustomVertex.PositionColored[WIDTH * HEIGHT];

            for (int x = 0; x < WIDTH; x++)
            {

                for (int y = 0; y < HEIGHT; y++)
                {
                    vertices[x + y * WIDTH].Position = new Vector3(x, y, heightData[x, y]);
                    vertices[x + y * WIDTH].Color = Color.White.ToArgb();
                }
            }

            vb.SetData(vertices, 0, LockFlags.None);
        }

        private void IndicesDeclaration()
        {
            ib = new IndexBuffer(typeof(int), (WIDTH - 1) * (HEIGHT - 1) * 6, device, Usage.WriteOnly, Pool.Default);
            indices = new int[(WIDTH - 1) * (HEIGHT - 1) * 6];

            for (int x = 0; x < WIDTH - 1; x++)
            {

                for (int y = 0; y < HEIGHT - 1; y++)
                {
                    indices[(x + y * (WIDTH - 1)) * 6] = (x + 1) + (y + 1) * WIDTH;
                    indices[(x + y * (WIDTH - 1)) * 6 + 1] = (x + 1) + y * WIDTH;
                    indices[(x + y * (WIDTH - 1)) * 6 + 2] = x + y * WIDTH;

                    indices[(x + y * (WIDTH - 1)) * 6 + 3] = (x + 1) + (y + 1) * WIDTH;
                    indices[(x + y * (WIDTH - 1)) * 6 + 4] = x + y * WIDTH;
                    indices[(x + y * (WIDTH - 1)) * 6 + 5] = x + (y + 1) * WIDTH;
                }
            }
            ib.SetData(indices, 0, LockFlags.None);
        }

        private void LoadHeightData()
        {
            int offset;
            byte dummy;

            FileStream fs = new FileStream("dss1.bmp", FileMode.Open, FileAccess.Read);
            BinaryReader r = new BinaryReader(fs);

            for (int i = 0; i < 10; i++)
            {
                dummy = r.ReadByte();
            }

            offset = r.ReadByte();
            offset += r.ReadByte() * 256;
            offset += r.ReadByte() * 256 * 256;
            offset += r.ReadByte() * 256 * 256 * 256;

            for (int i = 0; i < 4; i++)
            {
                dummy = r.ReadByte();
            }

            WIDTH = r.ReadByte();
            WIDTH += r.ReadByte() * 256;
            WIDTH += r.ReadByte() * 256 * 256;
            WIDTH += r.ReadByte() * 256 * 256 * 256;

            HEIGHT = r.ReadByte();
            HEIGHT += r.ReadByte() * 256;
            HEIGHT += r.ReadByte() * 256 * 256;
            HEIGHT += r.ReadByte() * 256 * 256 * 256;

            heightData = new int[WIDTH, HEIGHT];
            for (int i = 0; i < (offset - 26); i++)
            {
                dummy = r.ReadByte();
            }

            for (int i = 0; i < HEIGHT; i++)
            {
                for (int y = 0; y < WIDTH; y++)
                {
                    int height = (int)(r.ReadByte());
                    height += (int)(r.ReadByte());
                    height += (int)(r.ReadByte());
                    height /= 8;
                    heightData[WIDTH - 1 - y, HEIGHT - 1 - i] = height;
                }
            }

        }

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            device.Clear(ClearFlags.Target, Color.DarkSlateBlue, 1.0f, 0);

            device.BeginScene();
            device.VertexFormat = CustomVertex.PositionColored.Format;
            device.SetStreamSource(0, vb, 0);
            device.Indices = ib;

            //device.Transform.World = Matrix.Translation(-HEIGHT / 2, -WIDTH / 2, 0);
            device.Transform.World = Matrix.Translation(-HEIGHT / 2, -WIDTH / 2, 0) * Matrix.RotationZ(angle);            
            device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, WIDTH * HEIGHT, 0, indices.Length / 3);
            device.EndScene();

            device.Present();

            this.Invalidate();
            //angle += 0.05f;
            ReadKeyboard();
        }

        public void InitializeKeyboard()
        {
            keyb = new Microsoft.DirectX.DirectInput.Device(SystemGuid.Keyboard);
            keyb.SetCooperativeLevel(this, CooperativeLevelFlags.Background | CooperativeLevelFlags.NonExclusive);
            keyb.Acquire();
        }

        private void ReadKeyboard()
        {
            KeyboardState keys = keyb.GetCurrentKeyboardState();
            if (keys[Key.Delete])
            {
                angle += 0.03f;
            }
            if (keys[Key.Next])
            {
                angle -= 0.03f;
            }
        }
    }
}

09.06.2019 - 01:21 Uhr

4.7.2 wird normalerweise verwendet.

05.06.2019 - 06:43 Uhr

Nachdem ich mal das .NET-Framework 2.0 benutzte, scheint die Sache auf einmal zu funktionieren.

31.05.2019 - 13:48 Uhr

Sobald ich die Zeilen our_dx_form.InitializeDevice(); und Application.Run(our_directx_form); vertausche, dann zeigt es mir keine Form mehr an.

Muss mich zuerst mal an dieses Forum gewöhnen 😃

31.05.2019 - 03:52 Uhr

Versuche Anhand der Beispiele von http://www.riemers.net/eng/Tutorials/DirectX/Csharp/Series1/tut2.php das DirectX einzubinden. Bisher ohne Erfolg, hier der Code:


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;

namespace TestDirectX1
{
    public partial class Form1 : Form
    {
        private Device device;

        public Form1()
        {
            InitializeComponent();
        }

        public void InitializeDevice()
        {
            PresentParameters presentParams = new PresentParameters();
            presentParams.Windowed = true;
            presentParams.SwapEffect = SwapEffect.Discard;

            device = new Device(0, DeviceType.Reference, this, CreateFlags.SoftwareVertexProcessing, presentParams);
        }



        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            device.Clear(ClearFlags.Target, Color.DarkSlateBlue, 1.0f, 0);
            device.Present();
        }

    }
}

Im Program.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TestDirectX1
{
    static class Program
    {
        /// <summary>
        /// Der Haupteinstiegspunkt für die Anwendung.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            //Application.Run(new Form1());

            using (Form1 our_directx_form = new Form1())
            {
                Application.Run(our_directx_form);
                our_directx_form.InitializeDevice();
            }
        }
    }
}

Die Applikation startet, aber die Software geht in eine Dauerschleife.
Wo ist der Fehler?

23.07.2012 - 23:16 Uhr

Problem gelöst, habe wahrlich das gleiche Bild gezeichnet...

Vielen Dank für den Tipp 🙂

22.07.2012 - 16:18 Uhr

Hallo
Folgendes Problem:

Habe eine Imagelist dazu ein Panel erstellt. Es wird immer nur 1 Bild angezeigt, das letzte welches im Code aufgerufen wird.

Meine Frage:
Wie ist es möglich, mehrere Bilder in einem Panel anzuzeigen? Geht das überhaupt?

       public Form8()
        {
            InitializeComponent();


            imageList2.ImageSize = new Size(128, 128);
            imageList2.TransparentColor = Color.White;
            

            // Get a Graphics object from the form's handle.
            Graphics theGraphics = Graphics.FromHwnd(this.Handle);


            imageList2.Images.Add(Image.FromFile("c:\\DSS-Schriftzug Neu.bmp"));
            panel1.BackgroundImage = imageList2.Images[0];

            imageList2.Draw(theGraphics, new Point(85, 85), 0);

            imageList2.Images.Add(Image.FromFile("c:\\dietsche bruno.jpg"));            
            panel1.BackgroundImage = imageList2.Images[1];
                                  
            
            imageList2.Draw(theGraphics, new Point(85, 185), 0);


            panel1.Refresh();

            }
11.07.2012 - 05:02 Uhr

Hallo

Versuche in einer ListView die Daten mittels FindItemWithText auszulesen.
Dabei wird aber nicht immer alles gefunden.
Wie ist es möglich, die ListView komplett zu durchsuchen?

Hier mein Code, welcher aber nicht so recht funktioniert.

            ListViewItem foundItem = listView1Suchen.FindItemWithText(textBox1.Text, true, 0,true);

            if (foundItem != null)
            {
                listView1Suchen.SelectedIndices.Add(foundItem.Index);
                listView1Suchen.EnsureVisible(foundItem.Index);
            }

Vielen Dank
DSS