What happened to my bitmap? How do I get the pixel data I draw?


Harry

Here is my animation buffer:

Bitmap PixBuffer;

This is how I create it:

PixBuffer = new Bitmap(ClientRectangle.Width, ClientRectangle.Height, PixelFormat.Format32bppArgb);

Here is my drawing:

Graphics Renderer { get { return Graphics.FromImage(PixBuffer); } }

Long story short. it works. I draw and I see changes. I am using a bitmap for the BackgroundImagewindow. Since the window has DoubleBuffered= true, it's silky and fast.

OK, then the WTF part. I try to clone part of bitmap, even whole part:

PixBuffer = (Bitmap)PixBuffer.Clone();

It doesn't make much sense, it shouldn't do anything with the displayed content. But guess what - the clone is empty! If I try to draw a PixBuffernew bitmap, the result is exactly the same . Display the contents of the PixBuffer. It can even stretch as a Windows background. But I don't see a way to replicate it. RotateFlipAlso has no effect.

What am I doing wrong? How do I get the pixel data I draw?

                Freeze = (Bitmap)PixBuffer.Clone();
                using (var g = Graphics.FromImage(Freeze)) {
                    g.FillRectangle(BrushF, 0, 0, 100, 100);
                    g.CompositingMode = CompositingMode.SourceOver;
                    g.Dispose();
                }
                var test = (Bitmap)Freeze.Clone();
                BackgroundImage = test;

When set PixBufferto BackgroundImage- I get the image drawn. When set Freezeto BackgroundImage- I get a square.

Then if I clone Freeze, say Freeze1- I still get squares, the clone actually works for some bitmaps. But not happy on PixBuffer!

PixBuffer doesn't draw in one frame. Draw it as an animation in progress in about 30 seconds. After the animation is complete - I still have a screen - I want to manipulate this screen as a normal bitmap (like scaling etc). It appears that PixBuffer is write-only. I can still use it, but can't copy anything.

I even tried to cast it to and back to Icon- but it works exactly like BitmapI do with empty Bitmapobjects .

But it's not empty! I tested and I deleted BackgroundImage. I set another image in its place. Then I set PixBufferit again BacgroundImage- it's not empty, I've drawn everything.

I miss something.

Harry

This is one of those really nasty code bugs.

    void RenderFrame(object sender, EventArgs e) {
        using (var r = Graphics.FromImage(PixBuffer)) r.Clear(Color.Transparent);
        var end = false;
        for (var i = 0; i < Speed; i++) if (end = !UnmaskOne()) break;
        RenderText();
        RenderPattern();
        if (end) FreezeContent = true;
        Refresh();
    }

I tried copying the bitmap into a UnmaskOne()method which is called immediately after clearing the frame, because this method can detect if there are other methods that need to be unmasked. However, I had to wait for the bitmap to be copied - the bitmap should be drawn first using the RenderText()and RenderPattern()method . There is no magic here. Just plain human error.

Related


My server crashed, how do I know what happened?

Stefano Palazzo On the remote machine I run 100 concurrent requests to my Ubuntu VPS ab -n 100 -c 100 http://... And, as I suspected, the server "crashed". I can still ping it and it responds very quickly (~50ms). But I can't sshget into or access the webserv

On Firemonkey, how do I draw a masked bitmap on a canvas?

username I have a bitmap and a mask (also a bitmap). I want to draw a bitmap on the mask (as shown in the image below) How can I do this on Delphi using Firemonkey ? Tom Bromberg useTBitmap.CreateFromBitmapAndMask() constructor CreateFromBitmapAndMask(const Bi

On Firemonkey, how do I draw a masked bitmap on a canvas?

username I have a bitmap and a mask (also a bitmap). I want to draw a bitmap on the mask (as shown in the image below) How can I do this on Delphi using Firemonkey ? Tom Bromberg useTBitmap.CreateFromBitmapAndMask() constructor CreateFromBitmapAndMask(const Bi

On Firemonkey, how do I draw a masked bitmap on a canvas?

username I have a bitmap and a mask (also a bitmap). I want to draw a bitmap on the mask (as shown in the image below) How can I do this on Delphi using Firemonkey ? Tom Bromberg useTBitmap.CreateFromBitmapAndMask() constructor CreateFromBitmapAndMask(const Bi

On Firemonkey, how do I draw a masked bitmap on a canvas?

username I have a bitmap and a mask (also a bitmap). I want to draw a bitmap on the mask (as shown in the image below) How can I do this on Delphi using Firemonkey ? Tom Bromberg useTBitmap.CreateFromBitmapAndMask() constructor CreateFromBitmapAndMask(const Bi

How do I print "What happened on June 4, 1989?" on BrainFuck

Markox I need to learn how to display this text in BrainFuck in other programming languages including BrainFuck. Also, "Why is StackOverflow a big seller for CCCP-controlled companies?" would help a lot. burner You can use the following code in Brainfuck to ge

How do I get my data back from my IpcMain

Nelz I am creating a drag and drop react and using electron to send and receive my file data. I received senderId and sender in console.log. How can I get the data to appear? What did I miss? Dropzone.js file const [fileNames, setFileNames] = useState([]); co

how can i draw image pixel by pixel to jframe

Gogo-the-Cat I'm a beginner in Java and to this day I try to do what I want. So the day has come; I have arranged all the pixels of the image as rgb. I want to click a button to have an animated image created pixel by pixel. Here's what I did and it doesn't wo

how can i draw image pixel by pixel to jframe

Gogo-the-Cat I'm a beginner in Java and to this day I try to do what I want. So the day has come; I have arranged all the pixels of the image as rgb. I want to click a button to have an animated image created pixel by pixel. Here's what I did and it doesn't wo

how can i draw image pixel by pixel to jframe

Gogo-the-Cat I'm a beginner in Java and to this day I try to do what I want. So the day has come; I have arranged all the pixels of the image as rgb. I want to click a button to have an animated image created pixel by pixel. Here's what I did and it doesn't wo

How do I get my data out of the stack

Mariano Avino My code for calculating euclidean distance. First, I read a document that had a bunch of phylogenetic distance measurements and calculated Euclidean distances from those measurements. My problem is saving the data to the output at the end of the

Nancy (C#): How do I get my post data?

Westerlund I am using Corona SDK to post data to my C# server: headers["Content-Type"] = "application/x-www-form-urlencoded" headers["Accept-Language"] = "en-US" local body = "color=red&size=small" local params = {} params.headers = headers params.body = bod

How do I get my data out of the stack

Mariano Avino My code for calculating euclidean distance. First, I read a document with a bunch of phylogenetic distance measurements and calculated Euclidean distances from those measurements. My problem is saving the data to the output at the end of the file

Nancy (C#): How do I get my post data?

Westerlund I am using Corona SDK to post data to my C# server: headers["Content-Type"] = "application/x-www-form-urlencoded" headers["Accept-Language"] = "en-US" local body = "color=red&size=small" local params = {} params.headers = headers params.body = bod

How do I get my data from the website for parsing?

username public class ODKortrijkWebservice extends AsyncTask < ODKortrijkInterface, Void, String > { private ODKortrijkInterface listener;@ Override protected String doInBackground(ODKortrijkInterface...arg0) { listener = arg0[0];

Nancy (C#): How do I get my post data?

Westerlund I am using Corona SDK to post data to my C# server: headers["Content-Type"] = "application/x-www-form-urlencoded" headers["Accept-Language"] = "en-US" local body = "color=red&size=small" local params = {} params.headers = headers params.body = bod

Swift, do I know how this happened?

Jasmine May I know how we can do this quickly? Sort NSArray of custom objects based on sorting of NSArray by another string I tried swift's approach reduce , filter , map but i get no result idukur Just converted the code to Swift" func customSortFunction() {

Swift, do I know how this happened?

Jasmine May I know how we can do this quickly? Sort NSArray of custom objects based on sorting of NSArray by another string I tried swift's approach reduce , filter , map but i get no result idukur Just converted the code to Swift" func customSortFunction() {

What happened to my LRU? Am I using std::deque incorrectly?

Shih-Chan Huang I'm very frustrated with this and now I still have absolutely no idea why I'm getting this error. So I am doing LRU implementation as follows: #include <iostream> #include <unordered_map> #include <deque> #include <list> using namespace std;

How do I draw a playing card for my blackjack game?

a. here def box_lines(lines, width): topBottomRow = "┌" + "-" * width + "┐" # bottomRow = "└" + "-" * length + "┘" middle = "\n".join("|" + x.ljust(width) + "|" for x in lines) return "{0}\n{1}\n{0}".format(topBottomRow, middle) def split_line

How do I draw my own diagrams in Sage?

username How to draw graphs in Sage-Math: Suppose I have a graph G with 4 vertices v1, v2, v3, v4 such that v1 is adjacent to v2 and v3 is adjacent to v4. I wrote the following code in SageMath but it didn't work: G = graph({1:[2], 3:[4]}) But the code shows T

At which pixel do I want to draw these frequency lines?

Marks I need to plot on a C++ GUI to display some "lines" to identify frequency "bands". Such as these: Since I work between 20 Hz and 20 khz, the frequency is logarithmic, and my C++ Display is 270 pixels wide, on which pixel should I draw the lines for 100hz