|
Lookup "simulated annealing" - it's a good algorithm for laying out all kinds of data, from map labels to graphs.
Cheers,
Drew.
|
|
|
|
|
|
There 2 32bpp bitmaps with some images:
bitmap1
bitmap2
and graphics object g1 created from bitmap1
I set individualy alpha values in bitmap2 using LockBits:
Gdiplus::BitmapData bitmapData;
Gdiplus::Status s = pBitmap->LockBits(&Gdiplus::Rect(0, 0, pBitmap->GetWidth(), pBitmap->GetHeight()),
Gdiplus::ImageLockModeWrite | Gdiplus::ImageLockModeRead,
PixelFormat32bppRGB, &bitmapData);
if (s == Gdiplus::Ok) {
unsigned int* pPixels = (unsigned int *)bitmapData.Scan0;
for (unsigned int i = 0; i < bitmapData.Height; i++) {
for (unsigned int j = 0; j < bitmapData.Width; j++) {
if (mask(i, j) > 0)
pPixels[j] &= 0xFFFFFFFF;
else
pPixels[j] = 0x00FFFFFF;
}
pPixels += bitmapData.Stride / 4;
}
pBitmap->UnlockBits(&bitmapData);
}
And then draw it on bitmap1 using g1. But the alpha blending does not happen?
chesnokov
|
|
|
|
|
Chesnokov Yuriy wrote: Gdiplus::Status s = pBitmap->LockBits(&Gdiplus::Rect(0, 0, pBitmap->GetWidth(), pBitmap->GetHeight()),
Gdiplus::ImageLockModeWrite | Gdiplus::ImageLockModeRead,
PixelFormat32bppRGB, &bitmapData);
Shouldn't that be Format32bppArgb ?
The pBitmap bitmap must be Format32bppArgb as well.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
you're the MVP.
Muchos gracias!
I do not believe how can I omited that ARG in this call? They were all ARGB created and cloned, but that single LockBits somehow avoided ARGB. Ohhh
Чесноков
|
|
|
|
|
Hi! I'm using Visual C++ 2005 Express Edition and I am trying to create an application that uses DirectSound. I found on DirectSound Documentation how to initiate it, but I still have some problems. When I initiate last member of DSBUFFERDESC (the struct that describes the characteristics of a new buffer), i get this error:
1>main.obj : error LNK2019: unresolved external symbol _GUID_NULL
referenced in function "void __cdecl InitDirectSound(struct HWND__ *)" (?InitDirectSound@@YAXPAUHWND__@@@Z)
Here is the code, where "GUID_NULL" (which is defined in dsound.h) appears:
DSBUFFERDESC pcDSPrimaryBufferDesc,
pcDSPrimaryBufferDesc.guid3DAlgorithm=GUID_NULL;
On my project Propetries>>Configuration Propetries>>Linker>>Input>>ADDITIONAL DEPENDENCIES I added dsound.lib, but on DirectX Documentation it says that some DirectSound functions use Dsound3d.dll as import library. Where should I add it? what did I missed?
Thank you in advance!
|
|
|
|
|
Member 3796009 wrote: On my project Propetries>>Configuration Propetries>>Linker>>Input>>ADDITIONAL DEPENDENCIES I added dsound.lib
Try adding Dxguid.lib as well.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I want to write a filter Driver for usb camera, but i don't how to do. anyone can help me? my email : forever_28@yahoo.cn
|
|
|
|
|
I want to build a space ship that flies me to Ganymed, but I don't know how to do. Anyone can help me? my email: forever_dumb@yahoo.cn
|
|
|
|
|
Hi!
I have some question about vista DWM and related feature.
My project wanna a feature that all output of screen be stored in an offscreen buffer, then a program modify the buffer, for example, twist the screen image or make output brighter or darker, at last the modified result be sent to the real user screen.
It is just something like flip3d in vista.
Do you think it is possible to achieve by using some windows API?
Please give me some suggestion
Thank you!!
|
|
|
|
|
I am using directx9 and Visual c++ for my project. I am trying to display a mesh loading from *.x file. The mesh object has texturing object. When I am trying to render the meash there is a background containing one texture from the mesh file. The problem is when I use color blending. If I desable color blending there is no pproblem.
|
|
|
|
|
hi, im trying to extract the alpha image from png image. Instead of using iterations pixel by pixel, is there anyother fast or good way to do this ?
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
I want to zoom in on a bitmap like Paint where the further you zoom in, the larger the individual pixels appear without any interpolation. This is how I thought about doing it. First, I would read the bitmap into an array. Then, I would custom draw each pixel with the appropriate color from the array as squares. The size of the squares would depend on the zoom level. This is probably the worst way of doing it, but I couldn't think of anything else. Maybe, somebody can suggest a better way?
|
|
|
|
|
|
I have tried using DrawImage, but it appears to scale with some sort of interpolation applied. I need to zoom in and see the individual pixels. In other words, the further that you zoom in, the larger a single pixel will be drawn.
|
|
|
|
|
Oh wait, I just saw that I could use NearestNeighbor for the inpterpolation mode. I believe this will solve my problem.
|
|
|
|
|
|
Hi
I am having 10 bmp files and i want to make 1 gif file out of that using GDI+. Each bmp file should be displayed for particular time period. I searched a lot but unable to find the answer. I want to do it in C++.
|
|
|
|
|
Hi all,
I have some problems with directshow filters. I have a device (webcam) that provide some directshow filters for Capture (Source Filter) and Decoder Filter. So with those filters, I can capture and display the video in my local computer.
But I want to get the data from output pin of the Capture filter and using my own RTP stack(symmetric RTP, non-directshow written as a dll) to send it to a remote computer. And in the remote computer, I want to use my RTP stack to receive the video packets and using Decoder Filter to decode the data? So can I do something like that (mixed directshow filters with non-directshow)?
Thank you very much,
DBQ.
|
|
|
|
|
To attach to the output pin of a filter, you'll need to write a filter[^]
or a DMO[^].
I personally use a custom frame grabber filter . The samples
from the grabber filter can be used any way I want, including packaging
and sending on the network.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I'm rewriting a legacy application in C#/WinForms. The previous application (circa Win16) has a feature where it will plot 500,000+ points of data in under two seconds on my development machine.
I've written a plot control in GDI+ that will plot the same data in about 8 seconds on my development machine. This is with the inner loop as optimized as I can possibly get it.
This increase in plot time is unacceptable. The legacy application was written using GDI which is hardware accelerated and GDI+ is generally not.
The two options to fix this as far as I can tell is to write the plotter in GDI or in DirectX. If I write it in GDI, is there documentation anywhere on using it in a C# control (I'd like to use C# types if possible)? Is DirectX overkill and is it fast enough in a managed environment? Is there a third option I'm not thinking of?
I'd appreciate any feedback you guys have on how best to approach this problem.
Thanks,
Aaron
modified 12-Jul-20 21:01pm.
|
|
|
|
|
Aaron Stubbendieck wrote: Is DirectX overkill and is it fast enough in a managed environment? Is there a third option I'm not thinking of?
Considering they use directx in video games I'm sure it is fast enough. I don't think being managed is the main problem actually because I wrote my own graphics work around in vb.net and it is probably >50 times faster than that (I'm not exagerating assuming you meant 500,000 pixels by "500,000 points") and it could probably be optimized further.
If you want a c# work around I found this article http://www.codeproject.com/KB/GDI-plus/csharpgraphicfilters11.aspx[^].
If you would like a copy of my vb.net work around I'd be glad to give it to you (it would be pretty strait forward to convert to c#). I've been meaning to write an article about it for about a year but never got around to writing it.
Mike
|
|
|
|
|
By 500k points I mean 500k x,y pairs, so probably more than 500k pixels.
I keep meaning to learn DX and I'd appreciate taking a look at what you've got to get me started.
Thank you
modified 12-Jul-20 21:01pm.
|
|
|
|
|
Aaron Stubbendieck wrote: I keep meaning to learn DX and I'd appreciate taking a look at what you've got to get me started.
What I wrote doesn't use directx but it is still lightning fast and could be optimited further. Basically I needed it for some image recognition/ai stuff I wanted to display for debugging purposes. The dotnet functions were way too slow on my old laptop.
I will post the code from my graphics module in the next post. If you would like to see it used in an example project I wrote that uses the module please let me know your email and I will send you a zip of my project.
Here's how it works:
1) ReadStream takes a filestream as an argument and reads the pixel and header data into pixelarray and header. If you are not planning to modify an existing bitmap just make an empty one of the dimensions you need to serve this purpose.
2) GetPixel & SetPixel are pretty strait forward. They read or write data into the pixelarray but the results of this are not immediately displayed (there's a reason for this).
3) WriteStream takes the data in the 2 dimensional array and produces a bitmap memorystream.
4) WriteToPictureBox is like WriteStream but it will display the results in a picturebox you specify.
WriteStream & WriteToPictureBox should not be called until after you write all the data because this is by far the slowest of the functions. So if you are drawing a graph call Setpixel for all of the dots and when you are done call WriteToPictureBox to display it. Don't call it after every SetPixel.
This is probably one of the reasons that my code is so fast. It avoids certain repeated calculation that the dotnet methods probably have to use since some of them refresh after every draw.
Please note the example only works for 24 bit bitmaps you will have to modify the code if you want to use other ones. Also pixelarray data starts at position 1x1, I skipped the 0 indexes of the array because I prefer base 1 arrays and I wrote this code for myself originally.
|
|
|
|
|
Please note the example only works for 24 bit bitmaps you will have to modify the code if you want to use other ones. Also pixelarray data starts at position 1x1, I skipped the 0 indexes of the array because I prefer base 1 arrays and I wrote this code for myself originally.
Public Module GraphicsIO
Private Header() As Byte
Private HeaderLen As Integer
Private PixelArray(,) As PixelStr
Public Width As Integer
Public Height As Integer
'reads the data from a filestream into the header and pixelarray
Public Sub ReadStream(ByVal fstream As IO.FileStream)
Dim bytearray() As Byte, len As Integer, rowoffset As Integer, offset As Integer
Dim n As Integer, x As Integer, y As Integer, padding As Integer
Dim remainder As Integer
len = fstream.Length
ReDim bytearray(len)
fstream.Read(bytearray, 0, len) 'copies file stream into an array
'this extracts header information
HeaderLen = System.BitConverter.ToInt32(bytearray, 10)
Width = System.BitConverter.ToInt32(bytearray, 18)
Height = System.BitConverter.ToInt32(bytearray, 22)
ReDim PixelArray(Width, Height)
'this copies the header information into its own array
ReDim Header(HeaderLen)
For n = 0 To (HeaderLen - 1)
Header(n) = bytearray(n)
Next
'each row in a bitmap file must be a multiple of 4
'If not empty padding bytes are added
'This takes that into account and calculates how many padding bytes were added
remainder = (Width * 3) Mod 4
If remainder > 0 Then
padding = 4 - remainder
Else
padding = 0
End If
'this extracts the data and puts it into a 2d array of structures representing the colors
For y = 1 To Height
rowoffset = ((y - 1) * ((3 * Width) + padding))
offset = rowoffset + HeaderLen
For x = 1 To Width
'bitmaps store colors in reverse order: blue, green, red
PixelArray(x, y).B = bytearray(offset) 'blue
offset += 1
PixelArray(x, y).G = bytearray(offset) 'green
offset += 1
PixelArray(x, y).R = bytearray(offset) 'red
offset += 1
Next
Next
End Sub
'displays the image on the picturebox
Public Sub WriteToPictureBox(ByVal pictbox As PictureBox)
Dim myimage As Image, mstream As New IO.MemoryStream
mstream = GraphicsIO.WriteStream(mstream)
myimage = Image.FromStream(mstream)
pictbox.Image = myimage
Form1.GloImage = myimage
End Sub
'creates a file stream from the pixelarray
Public Function WriteStream(ByVal mstream As IO.MemoryStream)
Dim rowoffset As Integer, offset As Integer, bytearray() As Byte, len As Integer
Dim n As Integer, x As Integer, y As Integer, padding As Integer
Dim remainder As Integer
'Each row in a bitmap file must be a multiple of 4
'If not empty padding bytes are added
'This takes that into account and calculates how many padding bytes to add
remainder = (Width * 3) Mod 4
If remainder > 0 Then
padding = 4 - remainder
Else
padding = 0
End If
len = HeaderLen + (Height * ((Width * 3) + padding))
ReDim bytearray(len)
'copies the header into the byte array
For n = 0 To (HeaderLen - 1)
bytearray(n) = Header(n)
Next
'this extracts the data from a 2d array of structures representing the colors
For y = 1 To Height
rowoffset = ((y - 1) * ((3 * Width) + padding))
offset = rowoffset + HeaderLen
For x = 1 To Width
'bitmaps store colors in reverse order: blue, green, red
bytearray(offset) = PixelArray(x, y).B
offset += 1
bytearray(offset) = PixelArray(x, y).G
offset += 1
bytearray(offset) = PixelArray(x, y).R
offset += 1
Next
Next
'copies the bytearray into the memory stream
mstream.Write(bytearray, 0, len)
Return mstream
End Function
'reads a pixel
Public Sub GetPixel(ByVal x As Integer, ByVal y As Integer, ByRef r As Integer, ByRef g As Integer, ByRef b As Integer)
Dim pixel As PixelStr
pixel = PixelArray(x, y)
r = pixel.R
g = pixel.G
b = pixel.B
End Sub
'reads a pixel
Public Function GetPixel(ByVal x As Integer, ByVal y As Integer) As PixelStr
Dim pixel As PixelStr
pixel = PixelArray(x, y)
Return pixel
End Function
'writes a pixel
Public Sub SetPixel(ByVal x As Integer, ByVal y As Integer, ByVal r As Integer, ByVal g As Integer, ByVal b As Integer)
PixelArray(x, y).R = r
PixelArray(x, y).G = g
PixelArray(x, y).B = b
End Sub
Public Structure PixelStr
Public R As Byte 'red
Public G As Byte 'green
Public B As Byte 'blue
End Structure
End Module
|
|
|
|
|