|
Wow that worked... You're a lifesaver and a genius.
I wouldn't have thought that could fix it either but I was willing to try anything, so thanks for suggesting what I thought didn't matter.
|
|
|
|
|
Cool! I had no idea using the properties in the loop would be that slow!
Good to know!
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
I'll take a WILD stab at the C# syntax LOL...
public static RGBQUAD[] RGBQUADFromColorArray(Bitmap bmp)
{
int bits = Tools.BitsFromPixelFormat(bmp.PixelFormat);
if (bits <= 8)
{
RGBQUAD[] rgbArray = new RGBQUAD[1 << bits];
ColorPalette palette = bmp.Palette;
Color[] palcolors = palette.Entries;
for(int i=0; i < palcolors.Length; i++)
{
rgbArray[i].rgbRed = palcolors[i].R;
rgbArray[i].rgbGreen= palcolors[i].G;
rgbArray[i].rgbBlue = palcolors[i].B;
}
return rgbArray;
}
return 0;
}
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Yep you got it, same thing I translated your C++ to.
In case you didn't see my above reply... You got it fixed thanks so much.
|
|
|
|
|
Hi fellows!
Did anyone of you ever something like a winamp credit window? (the 3D credits viewer when you click on "Nullsoft Winamp..." in the context menu).
Anyone seen some code for doing this in .NET?
Thank's in advance,
Stevie
|
|
|
|
|
SCENARIO
I have been learing to use C# and DirectX via small programs using the Express edition of c# 2005.
To take what I have learn't further I have decided to develop a small engine, it is nothing fancy and so far it is only Direct Draw, just developing my skills.
I have developed the engine as a class library that has methods such as
Graphics2D=sets up direct draw and creates 2 surfaces for double buffering
LoadImage=loads a file into an offscreen surface array and returns the index
LoadAnimImage=same but creates a frame array and color key for transparency
DrawImage(Index,etc)=Draws the indicated image from the surface array.
there is also an overloaded DrawImage which has a frame parameter added for drawing animations.
I also have a testing project that references the dll and uses its methods to show a scrolling background and an animated walking character with music.
MY PROBLEM
OK, all is working well, except that my surface array is static in the number of elements it has.
Here is the code that relates to my question
private Surface[] ImgList = new Surface[2];
public int LoadImage(string FileName)
{
sDesc.Clear();
sDesc.SurfaceCaps.OffScreenPlain = true;
ImgList[NumImages] = new Surface(FileName, sDesc, dddevice);
NumImages+= 1;
return NumImages;
}
public void DrawImage(int Image,int x,int y)
{
ssurf.DrawFast(0, 0, ImgList[Image-1],ImageRect,DrawFastFlags.DoNotWait);
}
As I said, the above works fine, but I now want to make the surface array dynamic using the ArrayList from the system.collection namespace
and here is my attempt
ArrayList al = new ArrayList();
public int LoadImage(string FileName)
{
sDesc.Clear();
sDesc.SurfaceCaps.OffScreenPlain = true;
al.Add(new Surface(FileName, sDesc, dddevice));Add a surface to the array
NumImages+= 1;
return NumImages;
}
public void DrawImage(int Image, int x, int y)
{
ssurf.DrawFast(0,0,al[Image-1],ImageRect,DrawFastFlags.DoNotWait);
}
When I build that I get
cannot convert from system.array to microsoft.directx.directdraw.surface
error, among others which are related to the above error.
The error occurs in the DrawImage method
From the article I read about ArrayList collections I got the impression that the elements added to in an ArrayList could be of any type. Obviously I am mistaken, I only have a vague understanding of collections.
Can someone please tell me
What am I doing wrong ?
and more importantly for me, how can I make the above work?
Any help would be much appreciated.
-- modified at 17:23 Sunday 3rd June, 2007
|
|
|
|
|
In case anyone is interested in a solution I have figured out a workaround by modifying my static array solution.
I changed the array definition and the LoadImage method to use a new method called GrowImageArray.
This new method
Creates a new array to the new dimension
Copies all the surfaces from the old array into the new
Adds the new surface to the new array
Returns the new array to the LoadImage Method
I realize that this is probably not the best way to achieve my goal, but the 'best way' is not important to me at this stage because this is an experience gaining exercise
private Surface[] ImgList = null;
...
public int LoadImage(string FileName)
{
sDesc.Clear();
sDesc.SurfaceCaps.OffScreenPlain = true;
NumImages+= 1;
ImgList= GrowImageArray(FileName,ImgList, NumImages);
return NumImages;
}
private Surface[] GrowImageArray(string FileName,Surface[] pOldArray, Int32 pNewSize)
{
Int32 counter = 0;
Surface[] newArray = new Surface[pNewSize];
if (pNewSize > 1)
{
foreach (Surface item in pOldArray)
{
newArray[counter] = item;
counter += 1;
}
}
newArray[counter] = new Surface(FileName, sdesc, dddevice);
return newArray;
}
public void DrawImage(int Image,int x,int y)
{
ssurf.DrawFast(0, 0, ImgList[Image-1],ImageRect,DrawFastFlags.DoNotWait);
}
PS
I am still interested to find out how to achieve this with ArrayList?
|
|
|
|
|
What you are doing there is basically what a vector does. The C++ standard library has a vector class which is an array that grows. It uses a template to take a type, that is, you declare it like this:
vector<int> v = new vector<int>();
where int is the type. Now i don't know any C# but i had a look and found that indeed you can add any type to your ArrayList and that this is the C# equivalent to a vector. I think you function is quite good and if it works then that's even better
----------------------------------
Customer in computer shop: "Can you copy the Internet onto this disk for me?"
|
|
|
|
|
Thanks to VizCoder providing confirmation that ArrayList's are indeed any type I looked at my orriginal attempt again.
All I needed to do was change the DrawImage method to..
public void DrawImage(int Image, int x, int y)
{
ssurf.DrawFast(0,0,(Surface)al[Image-1],ImageRect,DrawFastFlags.DoNotWait);
}
Because the ArrayList object can be of any type I had to cast it as type surface when using it
(Surface)al[Image-1]
|
|
|
|
|
Saludos:
I will greatly appreciate any help you can provide with the following:
Currently I'm working on project to do zonal OCR on scanned images.
I'm in need to find a way to dectect blank images in order to exclude
them from the OCR process. I'm using CImage and CxImage to process
my images.Any suggestions?
Thanks Again;
Joe Gonzalez
|
|
|
|
|
Hi, i posted a question a few days ago about using SwapBuffers(). Well what i want to do it draw an image, warp it (using a grid of points and texture mapping the image to quads at each point), then copy that image and repeat. In other words, i want to continually copy the screen and render it back to the screen. Now i was doing that just fine by rendering straight to the screen but someone told me i should use pbuffers with shared lists. So i am, but how would i do the above? Here is some psudocode of what i think i should do
select pbuffer
draw warped texture of image
draw image on top of warped one
copy to texture
Now how do i get that to the screen? Just draw a quad textured with the image to fill the screen? If that is the case, why do i need the pbuffer.
I hope i have explained it well. Can anyone help
EDIT: by the way, i can't render directly to a texture since my hardware doesn't support it. I have to render to a scene (off screen) then copy to texture
-- modified at 21:05 Friday 1st June, 2007
Customer in computer shop: "Can you copy the Internet onto this disk for me?"
|
|
|
|
|
I am trying to understand the Math of a Camera in Computer Graphics.
Here is the question
If i have a camera a point a, How do I compute the view matrix so the camera looks at point b?
|
|
|
|
|
I am building a image cropper that should automatically detect the image boundry surrounded by white area and then crop it.
The question is:
how to detect the boundry of image surrounded by white area?
I have tried the following code with little success.
for (int j = 0; j < (height/2); j++)
{
count = 0;
for (i = 0; i < (width/2); i++)
{
color = grays.GetPixel(j,i);
if ((color.R == 255) && (color.B == 255) && (color.G == 255))
{
height_top = i;
width_left = j;
}
else
break;
}
}
This code should provide the upper left corner co-orninates but it does not.
Thanks in Advance.
Z.A
|
|
|
|
|
I think it would be easier to scan top-down horizontally until you find a non-white pixel. That
gives you the top. Then scan left-right vertically until you find a non-white pixel. That gives
you the left.
I think the code you've shown is just to get the top - maybe - unless there's colored pixels
higher on the right half of the image
Also, did you mean to put these arguments in this order? GetPixel(j,i);
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Simple bug... Unless I'm reading this wrong, that "break" in the else block is going to knock you right out of the "i" loop, but not out of the surrounding "j" loop. Hence it'll find the first non-white pixel, then continue on the next row.
Also, as another reply mentioned, check your i/j for row/column. I suggest using variable names like "row" and "col" to avoid confusion, because it looks like "j" is counting rows, but being placed in "width_left", and vice versa.
Oh, and if you want a more efficient algorithm, you might want to check pixels in a different order... What you're doing now is, using numbers to represent outer loop steps:
11111111
22222222
33333333
etc.
I think what you really want to do is:
12345
22345
33345
44445
55555
etc.
Little more complicated, but might work better.
|
|
|
|
|
Hi everyone...
I have a concrete problem but I will firstly introduce it in an abstract:
An algorithm scans a 24-bit bitmap data, an array of bytes. When the loop encounters a white pixel it adds the Point to the array of Points.
After the loop had scanned the entire bitmap I use the array of points to create the GraphicsPath
I draw the path and I get exactly what I want.
The problem is when checking for a hit test!
I use the myPath.IsVisible(point.X, point.Y) and here is where the problem occurs!
I have analyzed the array of points contained within the path object and have noticed that the myPath.IsVisible(point.X, point.Y) only return true in ONE SPECIAL CASE!
When the loop scans the first line of the bitmap and runs into a white pixel it will add that point to the array.
So this very point, the first white one in the first bitmap line, is the crucial one!
How? Well it seems that every point having its X coordinate greater than the very first point's X coordinate gets accounted form when calling myPath.IsVisible(point.X, point.Y) . This means that every point in the path's array of points whose X coordinate is lesser than the first co ordinate's X will not be accounted for the hit test!
This manifests in way that, if operating with an irregular elliptic resembling shape, only the right side is accounted for the hit test, not the left one!
I am more that happy to post the project for viewing and examining, it 100+ lines of code, but if someone has a solution to this I would be more than happy to hear it.
By the way, I have a good experience with wi32 HRGN structures, they did not give me such problems!
Thanks to everyone in advance!
|
|
|
|
|
This doesn't help you any, but I was involved in, tested, and comfirmed a bug in the GDI+
hittesting with regions. I still have the code that shows the flaw. It involved using a union
of two rect regions and hit testing in between them.
I wonder if it's related...
Good luck!
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Thanks, It helps me in the way that now I know I was right about the bug and can start searching for an alternative.
Right now I will attempt importing the win32 PtInRegion and utilize it.
If I get a success on this I will post the solution.
|
|
|
|
|
So, here is the famous solution, as I promised...
The case with my code was that I called myPath.AddLines(...) which caused an error!
The fact is that path wad drawing properly, i.e. its drawn shape is what I expected, though the path data was corrupted!
The solution was to create a 1x1 rectangle for each of the points (new Rectangle(points[i].X, points[i].Y, 1, 1) ) and then call myPath.AddRectangles(...)
After applying this method both, the drawn image and the hit testing worked just fine!
I hope this helps to someone.
By the way, after spending the entire day I got the solution of iterating through the monochrome (1 bit per pixel) bitmap data and checking if the pixel is black or white!
|
|
|
|
|
There are a lot of image libraries out there that handle converting image bit depths but is there any that solely focus on bit depth conversions?
I need something that can convert from 32bit with alpha to 8bit, 4bit, etc. and vice-versa preferably in C#.
I understand I should probably write these functions myself but it's extremely confusing working with the individual pixels etc. and I know that I could never make it as efficient as something that surely exists out there somewhere. I'm just having a hell of a time finding what I need. Even the image libraries I've found that include functions to convert bit depths convert to grayscale which is not what I need.
Thanks
|
|
|
|
|
hey all...
i've a question in the Photoshop application,
i've a small pic wz resolution 72 pixel/inch ... i wanna increase the resolution so that i can enlarge the pic but everytime i do that the pic gets blured & cant reach a tool 2 help me purify it .. does any1 has an answer 4 that or is it impossible 2 be done ??
thx ...
|
|
|
|
|
right click on the image frame.(i mean the frame at the top of the inserted image,which shows the image 's name.)there is option for image size.change it accordingly and save in appropriate format.
|
|
|
|
|
friendship wrote: i wanna increase the resolution so that i can enlarge the pic
You can't. It will only make the pixels bigger, which is why the picture is blurred. increasing the resolution would either make the picture smaller (to accomodate the higher resolution), or would require more image data if you were to make the picture larger.
Cheers,
Drew.
|
|
|
|
|
Hey frnds
Can any one tell me how to create 8 bit bitmap
thx in advance
Born To Code
|
|
|
|
|
You've asked this before....what part of the process is giving you trouble?
Do you want a device-dependent bitmap, a device-independent bitmap, ...??
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|