|
You could also just cast it... (This is a bit faster and uses less memory).
bitmap = (Bitmap)image;
Matthew Butler
|
|
|
|
|
Yes, most of the time that will work; what if the image happens to be a Metafile?
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
I've never used metafiles.
...but I suppose that would give an error.
Do people still use wmf/emf?
I've always concidered them quite an old (and outdated) format.
Matthew Butler
|
|
|
|
|
M. Butler wrote: Do people still use wmf/emf?
I don't know.
My point is: (Bitmap)Image.FromFile("test.WMF") could throw
since there is a difference between Bitmap and Image classes, so I prefer either the
constructor approach (hoping it is not too expensive) or an "is Bitmap" test (C#).
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Good example of why casts are dangerous.
C# really allows casts? hehe
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi all,
I'm trying to get the simplest of D3D9 programs working (coloured window). But keep getting this error when I run the SDK samples, and a website's sample i'm trying to follow.
Error 1 error LNK2019: unresolved external symbol _Direct3DCreate9@4 referenced in function "long __cdecl InitD3D(struct HWND__ *)" (?InitD3D@@YAJPAUHWND__@@@Z) CreateDevice.obj <br />
Followed by...
Error 2 fatal error LNK1120: 1 unresolved externals e:\Program Files\DirectX SDK\Samples\C++\Direct3D\Tutorials\Tut01_CreateDevice\Debug\CreateDevice.exe 1 <br />
By trial and error, I think its this line thats screwing it up...
d3d = Direct3DCreate9(D3D_SDK_VERSION);
Any ideas on how to fix this?
Mark.
|
|
|
|
|
Have you linked to d3d9.lib?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Yea I think I did it right...
I had put:
#pragma comment(lib, "d3d9.lib");
in my code.
If you want to review the whole program, you can find it here.
|
|
|
|
|
MarkBrock wrote: Yea I think I did it right...
If it linked, then it's good!
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I have a very big view (i.e. city) with so many detailes on it, and it consumes time to draw/redraw it.
My problem is: to select a street from that city, I have to ReDraw the scene/the whole city to do the picking and see the detailes of that street.
Does any one know how to do the selection / picking without redrawing every thing ?
Thank you
|
|
|
|
|
belloSoft wrote: My problem is: to select a street from that city, I have to ReDraw the scene/the whole city to do the picking and see the detailes of that street.
Does any one know how to do the selection / picking without redrawing every thing ?
There are two ways to do picking, three if you count hybrids, but we'll stick with two. One uses the draw cycle evaluating which pixel you touched and what triangle it belongs to, and what group that triangle lies within, etc. That is hardware based and limited by the options available in hardware. http://web.engr.oregonstate.edu/~mjb/cs553/Handouts/Picking/picking.pdf[^] I assume from your message you are doing this.
The second type is via proximity or at least via spatial zone. There are many algorithms a google on "ray intersection octree" or "ray intersection triangle" will produce many ansers. For instance: http://giig.ugr.es/~rgarcia/Poster.pdf[^] You can also do cheap bounding box tests mathematically for large regions. A quad-tree search within a scene for a "picked" locaton can quickly differenciate what object (or objects) you are looking at, and then you can either do a ray-triangle test to find a specific triangle of that subset, or an OpenGL pick of ONLY those few objects of relative usefullness.
There is also obscuration testing. This is fairly new (last few generations) but certainly no longer leading edge stuff, but it will allow you to quickly reduce the objects being drawn to only those visible using an occlusion query. The more you can do to "cut down" what you draw the faster your draw-time. Why draw it at all if it is off the screen? why draw it if it is entirely hidden by another building? etc. Occlusion Query[^]
_________________________
Asu no koto o ieba, tenjo de nezumi ga warau.
Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)
|
|
|
|
|
Thank you !
I will try the first solution
|
|
|
|
|
You probably want to try using ray intersection tests (3d) or point in polygon tests. If drawing is slow then drawing related methods would be least appropriate.
Sounds like they are causing your problem already...
|
|
|
|
|
Hi!
I have to do some calculations of GLC matrix and textural features in C++, but I don't know how to read an image and processing it like a matrix. This is very simple in Matlab, but I don't know how to do it in C++.
|
|
|
|
|
In wich format do you have your Image?
JO
|
|
|
|
|
Hi,
I have to get some properties of image files. Image file can be in any format and the properties i need is listed below
BitDepth of the image...
ColorSpace of the Image... whether it is RGB,GrayScale,CMYK or...
Number of bands in the image...
thanks for your help...
sniper47
|
|
|
|
|
There might be something in the dotnet libary that can do this but I've never done that before so I don't know. I do know you can do it by opening a file as a file stream then reading the header for the file.
Basically the headers are usually different for different file types so you'll have to look up information on each of the file types you are interested in.
Hope this helps,
Mike
|
|
|
|
|
|
Thanks for your replys. i have tried this property but i couldnt find which code means which property.
sniper47 Computer Engineer
|
|
|
|
|
Hi,
AFAIK these properties are optional, and supported by JPEG only.
These are the propID, propName pairs I recovered from some code:
Hashtable propNames=new Hashtable();
propNames.Add(0x010E, "ImageDescription");
propNames.Add(0x010F, "EquipMake");
propNames.Add(0x0110, "EquipModel");
propNames.Add(0x0112, "Orientation");
propNames.Add(0x011A, "XResolution");
propNames.Add(0x011B, "YResolution");
propNames.Add(0x0132, "DateTime");
propNames.Add(0x0128, "ResolutionUnit");
propNames.Add(0x0131, "SoftwareUsed");
propNames.Add(0x0201, "JPEGInterFormat");
propNames.Add(0x0202, "JPEGInterLength");
propNames.Add(0x0213, "YCbCrPositioning");
propNames.Add(0x501B, "ThumbnailData");
propNames.Add(0x502D, "ThumbnailResolutionX");
propNames.Add(0x502E, "ThumbnailResolutionY");
propNames.Add(0x5090, "LuminanceTable");
propNames.Add(0x5091, "ChrominanceTable");
propNames.Add(0x829A, "ExifExposureTime");
propNames.Add(0x9003, "ExifDTOrig");
propNames.Add(0x9004, "ExifDTDigitized");
propNames.Add(0x9204, "ExifExposureBias");
propNames.Add(0x9209, "ExifFlash");
propNames.Add(0x927C, "ExifMakerNote");
propNames.Add(0x9286, "ExifUserComment");
propNames.Add(0xA002, "ExifPixXDim");
propNames.Add(0xA003, "ExifPixYDim");
and this shows the kind of code you will need to extract a property:
PropertyItem pi=image.GetPropertyItem(ID);
s="";
byte[] bb=pi.Value;
switch ((PropertyTagType)pi.Type) {
case PropertyTagType.Byte:
type="(byte)";
for (int i=0; i<bb.Length; i++) {
byte us=bb[i];
s+=" "+us.ToString("X2");
if (bb.Length==1) s+="("+us.ToString()+")";
}
break;
case PropertyTagType.ASCII:
type="(ASCII)";
s=" "+ASCIIencoding.GetString(pi.Value, 0, pi.Len-1);
break;
case PropertyTagType.Short:
type="(short)";
for (int i=0; i<bb.Length/2; i++) {
ushort us=BitConverter.ToUInt16(bb,2*i);
s+=" "+us.ToString("X4");
if (bb.Length==2) s+="("+us.ToString()+")";
}
break;
...
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Hi all,
I have loaded 3D model using Direct 3d retained mode. I have to display label for all faces available in a mesh.
Kindly tell me how to add a label for a face using Direct 3d retained mode.
|
|
|
|
|
I have some pretty basic code that loads a texture, and tries to display it all across my terrain, however, it does not seem to be working and I can't for the life of me figure out why.
The loading code is here:
ifstream texFile("brickbump.bmp");
if (texFile.is_open())
{
AUX_RGBImageRec* image = auxDIBImageLoad("brickbump.bmp");
glGenTextures(1, &m_textures[0]);
glBindTexture(GL_TEXTURE_2D, m_textures[0]);
glTexImage2D(GL_TEXTURE_2D, GL_RGB8, 3, image->sizeX, image->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, image->data);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
texFile.close();
free(image);
}
After this, I have my function that redraws everything. Since it is too long, here is the important snippet:
glBindTexture(GL_TEXTURE_2D, m_textures[0]);
QuadVNode* tempNode = m_terrain->Tree()->GetFirstNode();
QuadVNode* nextLineNode = tempNode->Bottom();
int count = 0;
while (nextLineNode)
{
glBegin(GL_TRIANGLE_STRIP);
while (tempNode)
{
glNormal3d(tempNode->m_nx, tempNode->m_ny, tempNode->m_nz);
if (count % 2 == 0)
glTexCoord2d(0.0f, 0.0f);
else if (count % 2 == 1)
glTexCoord2d(1.0f, 0.0f);
glVertex3d(tempNode->m_x, tempNode->m_height, tempNode->m_z);
tempNode = tempNode->Bottom();
glNormal3d(tempNode->m_nx, tempNode->m_ny, tempNode->m_nz);
if (count % 2 == 0)
glTexCoord2d(0.0f, 1.0f);
else if (count % 2 == 1)
glTexCoord2d(1.0f, 1.0f);
glVertex3d(tempNode->m_x, tempNode->m_height, tempNode->m_z);
tempNode = tempNode->Top()->Right();
count++;
}
glEnd();
tempNode = nextLineNode;
nextLineNode = nextLineNode->Bottom();
}
My problem is that it doesn't display the texture. All it does is draw it as if I had simply done glNormal/glVertex over and over again, discarding the glTex2Coord call in between. Another thing I should mention is that I do have glEnable(GL_TEXTURE_2D) somewhere in my initialization code. Also, it does actually find the texFile, and sets m_textures[0] to an unsigned value of 1 when I call glGenTextures().
|
|
|
|
|
Alright, this happened to be a fluke, but I went digging around in the documentation, and it was suggested that I use 0 for the second parameter to glTexImage2D, and now it works. I don't know where I came up with RGB_8 as the constant to use there, but this solves the problem.
|
|
|
|
|
I'm doing something with a bitmap and as many of you probably know the getpixel and setpixel functions are heinously slow so I'm simply opening the bitmap as a filestream and manipulating the bytes directly which is much faster. Anyways is there anyway I can display this filestream directly on a picuturebox without having to close the file then load it again from its location in the hard drive.
thanks,
Mike
|
|
|
|
|
Image.FromStream() accepts a FileStream.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|