|
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
|
|
|
|
|
Can u plz explain how to draw 8 bit bitmap using palette.
The bitmap should be of 256 color,
thnaks
|
|
|
|
|
I still don't know what type of bitmap you're using.
You draw 8-bit bitmaps the same as any bitmaps. You can use GetDeviceCaps(RASTERCAPS) to check
if the destination DC is a palette device. If it is, select your palette into it, call
RealizePalette() (usually), and draw the bitmap.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
thank u Sir,
but tell me how to know whether the destination DC is a palette device or not?
if not then how to set.
|
|
|
|
|
rahul.shendurnikar wrote: how to know whether the destination DC is a palette device or not?
if (GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE)
{
}
How to set it depends on the device. For a monitor, it's based on the video mode.
For a printer device it's based on the bitmap format selected into the dc. etc...
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
hey
my destination DC is not a palette device.
destination DC is my Monitor.
Can u plz send me code snipet which create 8 bit bitmap usning palette.
the palette aaray should be.....
static int ARGB[256][3] =
{
{0,0,0}, //0
{48,0,0}, //1
{48,48,48}, //2
{0,16,16}, //3
{32,32,32}, //4
{16,16,16}, //5
{0,48,0}, //6
{48,48,0}, //7
{0,48,48}, //8
{0,16,16}, //9
{80,80,80}, //10
{96,96,96}, //11
{96,96,96}, //12
{112,112,112}, //13
{128,128,128}, //14
{144,144,144}, //15
{160,160,160}, //16
{160,160,160}, //17
{176,176,176}, //18
{192,192,192}, //19
{208,208,208}, //20
{208,208,208}, //21
{208,208,208}, //22
{224,224,224}, //23
{224,224,224}, //24
{224,224,224}, //25
{240,240,240}, //26
{96,48,48}, //27
{96,48,0}, //28
{96,0,0}, //29
{96,0,96}, //30
{96,48,96}, //31
{160,0,96}, //32
{160,48,96}, //33
{160,0,32}, //34
{160,48,48}, //35
{160,48,0}, //36
{160,0,0}, //37
{160,96,96}, //38
{160,96,48}, //39
{160,96,0}, //40
{208,0,96}, //41
{208,48,96}, //42
{208,96,96}, //43
{208,96,0}, //44
{208,96,48}, //45
{208,48,48}, //46
{208,48,0}, //47
{208,0,0}, //48
{240,96,96}, //49
{240,0,112}, //50
{240,48,96}, //51
{240,0,96}, //52
{240,96,48}, //53
{240,96,0}, //54
{240,16,32}, //55
{240,80,80}, //56
{240,0,0}, //57
{240,128,128}, //58
{240,160,160}, //59
{240,160,160}, //60
{240,160,208}, //61
{240,96,208}, //62
{240,96,240}, //63
{224,16,208}, //64
{224,16,208}, //65
{240,0,176}, //66
{240,0,160}, //67
{240,48,160}, //68
{240,96,160}, //69
{208,0,144}, //70
{208,0,160}, //71
{208,48,160}, //72
{208,96,160}, //73
{240,0,208}, //74
{208,96,208}, //75
{208,0,208}, //76
{208,96,208}, //77
{208,48,208}, //78
{240,0,240}, //79
{240,48,240}, //80
{240,160,240}, //81
{240,208,240}, //82
{208,160,96}, //83
{208,160,48}, //84
{208,160,0}, //85
{208,160,48}, //86
{208,160,160}, //87
{240,208,160}, //88
{240,208,160}, //89
{240,208,192}, //90
{240,208,208}, //91
{208,160,208}, //92
{176,160,144}, //93
{208,208,160}, //94
{208,208,160}, //95
{208,208,160}, //96
{240,240,208}, //97
{240,240,208}, //98
{96,96,0}, //99
{96,96,48}, //100
{0,96,0}, //101
{48,96,0}, //102
{0,96,48}, //103
{48,96,48}, //104
{0,128,0}, //105
{96,160,48}, //106
{96,160,96}, //107
{48,160,96}, //108
{0,160,96}, //109
{0,160,48}, //110
{48,160,48}, //111
{48,160,0}, //112
{0,160,0}, //113
{48,208,0}, //114
{0,208,0}, //115
{96,208,0}, //116
{96,208,96}, //117
{96,208,96}, //118
{0,208,48}, //119
{48,208,48}, //120
{96,208,48}, //121
{0,208,96}, //122
{48,208,96}, //123
{0,240,0}, //124
{96,240,96}, //125
{48,240,48}, //126
{48,240,96}, //127
{0,240,96}, //128
{96,240,48}, //129
{96,240,0}, //130
{160,240,0}, //131
{160,240,48}, //132
{160,240,96}, //133
{192,224,192}, //134
{176,224,192}, //135
{176,224,192}, //136
{208,240,208}, //137
{208,240,0}, //138
{208,240,48}, //139
{208,240,96}, //140
{240,208,96}, //141
{240,208,48}, //142
{240,208,0}, //143
{128,128,0}, //144
{160,160,48}, //145
{160,160,64}, //146
{160,160,96}, //147
{176,192,0}, //148
{208,208,48}, //149
{208,208,96}, //150
{160,208,48}, //151
{160,208,96}, //152
{160,208,96}, //153
{160,208,0}, //154
{160,208,96}, //155
{240,160,96}, //156
{240,160,48}, //157
{240,160,0}, //158
{160,240,160}, //159
{240,240,0}, //160
{240,240,96}, //161
{240,240,48}, //162
{224,224,0}, //163
{160,240,160}, //164
{0,240,160}, //165
{48,240,160}, //166
{96,240,160}, //167
{48,240,160}, //168
{0,240,160}, //169
{48,208,160}, //170
{0,208,160}, //171
{0,208,160}, //172
{48,208,160}, //173
{96,208,160}, //174
{176,176,144}, //175
{48,96,96}, //176
{0,96,96}, //177
{0,128,128}, //178
{0,160,160}, //179
{96,160,160}, //180
{48,240,208}, //181
{0,240,208}, //182
{160,240,208}, //183
{0,208,208}, //184
{48,208,208}, //185
{96,208,208}, //186
{0,192,208}, //187
{160,240,240}, //188
{96,240,240}, //189
{0,240,240}, //190
{48,240,240}, //191
{96,240,240}, //192
{208,240,240}, //193
{208,240,240}, //194
{160,208,240}, //195
{160,208,240}, //196
{208,208,240}, //197
{160,160,208}, //198
{208,0,240}, //199
{208,160,240}, //200
{160,48,208}, //201
{160,0,208}, //202
{160,96,208}, //203
{208,96,240}, //204
{208,48,240}, //205
{176,80,192}, //206
{160,96,160}, //207
{160,0,160}, //208
{160,48,160}, //209
{128,0,128}, //210
{160,48,240}, //211
{160,0,240}, //212
{160,96,240}, //213
{96,0,160}, //214
{96,48,160}, //215
{48,0,96}, //216
{0,0,96}, //217
{0,48,96}, //218
{48,48,96}, //219
{0,0,112}, //220
{0,0,112}, //221
{0,0,128}, //222
{160,160,240}, //223
{48,48,160}, //224
{0,0,160}, //225
{0,48,160}, //226
{48,0,160}, //227
{48,96,160}, //228
{96,96,160}, //229
{0,96,208}, //230
{48,96,208}, //231
{0,0,208}, //232
{96,48,208}, //233
{48,48,208}, //234
{0,48,208}, //235
{0,0,240}, //236
{96,0,240}, //237
{96,96,240}, //238
{0,96,240}, //239
{96,48,240}, //240
{48,48,240}, //241
{48,96,240}, //242
{96,96,208}, //243
{96,160,240}, //244
{48,160,240}, //245
{0,160,240}, //246
{96,160,224}, //247
{96,160,224}, //248
{0,160,208}, //249
{96,160,208}, //250
{48,160,208}, //251
{0,192,224}, //252
{0,208,240}, //253
{48,208,240}, //254
{96,208,240} //255
};
thanks in advance..
|
|
|
|
|
Given your palette, here's one way:
LONG lImageWidth = 320;
LONG lImageHeight = 240;
WORD wBitsPerPixel = 8;
LONG lBytesPerRow = (((lImageWidth * (long)wBitsPerPixel + 31L) & (~31L)) / 8L);
BITMAPINFO *pbmi = (BITMAPINFO *)new BYTE[sizeof(BITMAPINFO) + sizeof(RGBQUAD) * 255];
memset(pbmi, 0, sizeof(BITMAPINFO));
pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
pbmi->bmiHeader.biWidth = lImageWidth;
pbmi->bmiHeader.biHeight = lImageHeight;
pbmi->bmiHeader.biPlanes = 1;
pbmi->bmiHeader.biBitCount = wBitsPerPixel;
pbmi->bmiHeader.biCompression = BI_RGB;
pbmi->bmiHeader.biSizeImage = lBytesPerRow * lImageHeight;
for (int i = 0; i < 256; i++)
{
pbmi->bmiColors[i].rgbBlue = (BYTE)ARGB[i][2];
pbmi->bmiColors[i].rgbGreen = (BYTE)ARGB[i][1];
pbmi->bmiColors[i].rgbRed = (BYTE)ARGB[i][0];
pbmi->bmiColors[i].rgbReserved = 0;
}
BYTE* pBitmapBits;
HDC hdc = ::GetDC(0);
HBITMAP hBitmap = ::CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, &pBitmapBits, NULL, 0);
::ReleaseDC(0, hdc);
if (hBitmap)
{
memset(pBitmapBits, 0, pbmi->bmiHeader.biSizeImage);
...
...
::DeleteObject(hBitmap);
delete[] (BYTE *)pbmi;
}
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|