Click here to Skip to main content
15,899,580 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
GeneralRe: How to shift a bitmap efficiently (Spectrogram Application) Pin
Luc Pattyn19-Sep-10 17:11
sitebuilderLuc Pattyn19-Sep-10 17:11 
GeneralRe: How to shift a bitmap efficiently (Spectrogram Application) Pin
bimbambumbum19-Sep-10 17:32
bimbambumbum19-Sep-10 17:32 
AnswerRe: How to shift a bitmap efficiently (Spectrogram Application) Pin
Luc Pattyn19-Sep-10 17:48
sitebuilderLuc Pattyn19-Sep-10 17:48 
GeneralRe: How to shift a bitmap efficiently (Spectrogram Application) Pin
bimbambumbum19-Sep-10 17:57
bimbambumbum19-Sep-10 17:57 
AnswerRe: How to shift a bitmap efficiently (day 2) [modified] Pin
Luc Pattyn20-Sep-10 16:14
sitebuilderLuc Pattyn20-Sep-10 16:14 
GeneralRe: How to shift a bitmap efficiently (day 2) [modified] Pin
bimbambumbum20-Sep-10 17:54
bimbambumbum20-Sep-10 17:54 
GeneralRe: How to shift a bitmap efficiently (day 2) Pin
Luc Pattyn20-Sep-10 18:09
sitebuilderLuc Pattyn20-Sep-10 18:09 
GeneralRe: How to shift a bitmap efficiently (day 2) Pin
bimbambumbum21-Sep-10 11:23
bimbambumbum21-Sep-10 11:23 
Hi Luc

Here is the core of my bitmap shifting. If you run it you can see that the shifting flickers a little and I would like to avoid that.

Hope you have a simple way of getting rid of the flickering. Sorry for the messy code....Mind you I'm a newbie Smile | :)

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using fftwlib;


namespace GDI_evaluation
{
    public partial class Form1 : Form
    {
        Timer timer = new Timer();
        Graphics g;

        int XREF = 50;
        int YREF = 50;

        // Bitmap
        Bitmap myBitmap;
        Random rnd;
        int tIndx = 0;

        public Form1()
        {
            InitializeComponent();

            rnd = new Random();

            this.SetStyle(
           ControlStyles.UserPaint |
           ControlStyles.AllPaintingInWmPaint |
           ControlStyles.OptimizedDoubleBuffer, true);

            myBitmap = new Bitmap(768, 512, PixelFormat.Format24bppRgb);

            timer.Tick += new EventHandler(timer_tick);
            timer.Interval = 1000 / 25;      // opdater grafik 50 /sekund!!!
            timer.Enabled = true;
            timer.Start();
        }

        void timer_tick(object sender, EventArgs e)
        {
            this.Refresh(); // Update GUI
        }

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
        }

        protected override void OnPaint(PaintEventArgs pe)
        {
            g = pe.Graphics;

            Rectangle block1 = new Rectangle(XREF + tIndx, YREF, myBitmap.Width - tIndx, myBitmap.Height);
            g.DrawImage(myBitmap, block1, 0, 0, myBitmap.Width - tIndx, myBitmap.Height, GraphicsUnit.Pixel);
            Rectangle block2 = new Rectangle(XREF, YREF, tIndx, myBitmap.Height);
            g.DrawImage(myBitmap, block2, myBitmap.Width - tIndx, 0, tIndx, myBitmap.Height, GraphicsUnit.Pixel);


            int tIndx2 = tIndx - 1;
            if (tIndx2 < 0)
                tIndx2 = myBitmap.Width - 1;

            // Insert new FFT data
            for (int ii = 0; ii < myBitmap.Height; ii++)
                myBitmap.SetPixel(myBitmap.Width - 1 - tIndx2, ii, Color.FromArgb(rnd.Next(255), rnd.Next(255), rnd.Next(255)));

            if (++tIndx == myBitmap.Width)
                tIndx = 0;

        }
    }
}

GeneralRe: How to shift a bitmap efficiently (day 2) [modified] Pin
Luc Pattyn21-Sep-10 11:41
sitebuilderLuc Pattyn21-Sep-10 11:41 
GeneralRe: How to shift a bitmap efficiently (day 2) Pin
bimbambumbum21-Sep-10 11:45
bimbambumbum21-Sep-10 11:45 
AnswerRe: How to shift a bitmap efficiently (day 2) Pin
Luc Pattyn20-Sep-10 18:29
sitebuilderLuc Pattyn20-Sep-10 18:29 
GeneralRe: How to shift a bitmap efficiently (day 2) Pin
bimbambumbum22-Sep-10 13:01
bimbambumbum22-Sep-10 13:01 
GeneralRe: How to shift a bitmap efficiently (day 3) Pin
Luc Pattyn22-Sep-10 13:06
sitebuilderLuc Pattyn22-Sep-10 13:06 
QuestionDataBinding-aware (dependency)objects? Pin
Don Rolando19-Sep-10 3:32
Don Rolando19-Sep-10 3:32 
Questionpicturebox.visible problem Pin
bimbambumbum18-Sep-10 15:36
bimbambumbum18-Sep-10 15:36 
AnswerRe: picturebox.visible problem Pin
bimbambumbum18-Sep-10 15:42
bimbambumbum18-Sep-10 15:42 
GeneralRe: picturebox.visible problem Pin
DaveyM6918-Sep-10 20:29
professionalDaveyM6918-Sep-10 20:29 
AnswerRe: picturebox.visible problem Pin
Luc Pattyn19-Sep-10 3:44
sitebuilderLuc Pattyn19-Sep-10 3:44 
QuestionChoice of .NET Framework version Pin
fdsfsa76f7sa615-Sep-10 21:31
fdsfsa76f7sa615-Sep-10 21:31 
AnswerRe: Choice of .NET Framework version Pin
Kubajzz16-Sep-10 0:16
Kubajzz16-Sep-10 0:16 
AnswerRe: Choice of .NET Framework version Pin
Pete O'Hanlon16-Sep-10 1:28
mvePete O'Hanlon16-Sep-10 1:28 
AnswerRe: Choice of .NET Framework version Pin
The Man from U.N.C.L.E.20-Sep-10 12:06
The Man from U.N.C.L.E.20-Sep-10 12:06 
QuestionProblem adding FFTW.dll as reference. [modified] Pin
bimbambumbum15-Sep-10 14:54
bimbambumbum15-Sep-10 14:54 
AnswerRe: Problem adding FFTW.dll as reference Pin
Luc Pattyn15-Sep-10 16:13
sitebuilderLuc Pattyn15-Sep-10 16:13 
GeneralRe: Problem adding FFTW.dll as reference Pin
bimbambumbum18-Sep-10 15:31
bimbambumbum18-Sep-10 15:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.