|
dapa wrote: Hello! I need the sample of code of "warp mode image transformation" in photoshop.
http://en.wikipedia.org/wiki/Spline_interpolation[^]
_________________________
Asu no koto o ieba, tenjo de nezumi ga warau.
Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)
John Andrew Holmes "It is well to remember that the entire universe, with one trifling exception, is composed of others."
|
|
|
|
|
|
Thank you, Y will to try to do it
|
|
|
|
|
As the subject says I'm looking for an algorithm to scan an image and extract the rectagles that have the same pixel color.
Thanks in advance.
modified on Monday, April 14, 2008 11:44 AM
|
|
|
|
|
Hi,
first of all we have a "math and algo" forum, you should ask there.
I don't know of any official algorithm that matches your request, but it sounds fairly
simple to me; here is some pseudo-code:
rectCollection=empty;
foreach (point P in image and not in rectCollection) {
w=number of identically colored points to the right of P
h=number of identically colored points below P
check rectangle at P with size (w,h) has homogeneous color
if so, add to rectCollection
if not, reduce w and or h based on the position of the first non-matching point
}
done!
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
This could work Luc, thank you, but it looks very inefficient. I have to do this at least twice every second.
|
|
|
|
|
Hi,
there may be better algorithms, it probably depends on the kind of image you are dealing with.
what is the image size?
make sure you use pointers, don't rely on Bitmap.GetPixel, that is way too slow.
are the consecutive images similar?
do the rectangles found have a good chance of being there again on the next image?
if so, make use of it!
you do realize there is no single solution to your problem? if you have
AA
AB
then you can describe it as:
1) A A
A B
2) AAA
A B
3) A A
A
A B
It might help if you describe the intended application a bit...
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
modified on Tuesday, April 15, 2008 8:05 PM
|
|
|
|
|
My friend and I were having an argument about the drawing speed of GDI+. First he presented the flicker problem, but I fixed that with
SetStyle(ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);
then, after awhile, he presented the following:
<br />
using System;<br />
using System.Drawing;<br />
using System.Drawing.Imaging;<br />
using System.Runtime.InteropServices;<br />
using System.Windows.Forms;<br />
<br />
namespace SlowGdi {<br />
public partial class SlowGdiForm : Form {<br />
<br />
private Random RandomSource = new Random();<br />
<br />
private int[] RandomPixels = new int[512 * 512];<br />
<br />
private Bitmap RandomBitmap = new Bitmap(512, 512);<br />
<br />
public SlowGdiForm()<br />
{<br />
InitializeComponent();<br />
this.Disposed += (sender, e) => this.RandomBitmap.Dispose();<br />
Application.Idle += (sender, e) => this.Invalidate();<br />
}<br />
<br />
private void SlowGdiForm_Paint(object sender, PaintEventArgs e)<br />
{<br />
for (int i = 0; i < RandomPixels.Length; i++) {<br />
this.RandomPixels[i] = this.RandomSource.Next();<br />
}<br />
var Locked = this.RandomBitmap.LockBits(new Rectangle(0, 0, 512, 512), ImageLockMode.WriteOnly, PixelFormat.Format32bppRgb);<br />
Marshal.Copy(this.RandomPixels, 0, Locked.Scan0, 512 * 512);<br />
this.RandomBitmap.UnlockBits(Locked);<br />
e.Graphics.DrawImage(this.RandomBitmap, 0, 0, 512, 512);
}<br />
<br />
private void SlowGdiForm_Load(object sender, EventArgs e)<br />
{<br />
SetStyle(ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);<br />
}<br />
}<br />
}<br />
<br />
This looks all cool, but do a quick Ctrl+Alt+Delete, and notice the 100% Processor Usage (50% on Dual Core)
Anyone have any idea on how to optimise the code to NOT annihilate the processor?
Thanks
- Reelix
P.S: Thread.Sleep(1); helps abit, but not all that much...
P.P.S: Apparently it works perfectly on Vista...
modified on Monday, April 14, 2008 7:58 AM
|
|
|
|
|
Reelix wrote: Application.Idle += (sender, e) => this.Invalidate();
it doesn't matter if you are doing GDI or OpenGL, this will run full out on any machine you are "allowed" to have full access to the CPU. You don't force a redraw on idle you force a redraw on vertical retrace or other unless you do want all the CPU.
|
|
|
|
|
HI ,
i want to do a project on graphics as part of my engineering course .
i have decided to do a project other than game ..i have to use all the basic algorithms and some of the in built functions that are available in turbo C ... please suggest me different topics on which i can do a project .. the code shoudnt exceed 900 lines ...
i have plans to do animation(changing the face with user interface) , simulating towers of hanoii problem ,etc ..suggest me better ideas/topics to do the same
thanks
|
|
|
|
|
Hello..
I have a problem about shading. Actually, I want to apply a phong shading to the 3d object.Here is the code:
#include "Global.h"<br />
#include "lightComponent.h"<br />
<br />
<br />
<br />
<br />
<br />
void setOrthographicProjection() <br />
{<br />
glMatrixMode(GL_PROJECTION);<br />
glPushMatrix();<br />
glLoadIdentity();<br />
gluOrtho2D(0, screen_width, 0, screen_height);<br />
glScalef(1, -1, 1);<br />
glTranslatef(0, -screen_height, 0);<br />
glMatrixMode(GL_MODELVIEW);<br />
} <br />
<br />
<br />
<br />
void resetPerspectiveProjection() <br />
{<br />
glMatrixMode(GL_PROJECTION);<br />
glPopMatrix();<br />
glMatrixMode(GL_MODELVIEW);<br />
}<br />
<br />
<br />
<br />
void renderBitmapString(float x, float y, void *font,char *string)<br />
{<br />
char *c;<br />
<br />
glRasterPos2f(x, y);<br />
for (c=string; *c != '\0'; c++) {<br />
glutBitmapCharacter(font, *c);<br />
}<br />
}<br />
<br />
<br />
<br />
<br />
void Myinit(void) <br />
{<br />
glClearColor (0.0, 0.0, 0.0, 1.0);<br />
glShadeModel (GL_SMOOTH);<br />
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);<br />
<br />
glMatrixMode(GL_PROJECTION); <br />
glLoadIdentity();<br />
gluPerspective(60,1.0,0.1,100); <br />
glMatrixMode(GL_MODELVIEW);<br />
<br />
<br />
init_light();<br />
<br />
glEnable(GL_LIGHTING);<br />
glEnable(GL_LIGHT0);<br />
glEnable(GL_COLOR_MATERIAL);<br />
<br />
glEnable(GL_DEPTH_TEST);<br />
glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
}<br />
<br />
<br />
<br />
void resize (int width, int height)<br />
{<br />
screen_width=width; <br />
screen_height=height; <br />
<br />
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); <br />
glViewport(0,0,screen_width,screen_height); <br />
<br />
glMatrixMode(GL_PROJECTION); <br />
glLoadIdentity(); <br />
gluPerspective(45.0f,(GLfloat)screen_width/(GLfloat)screen_height,1.0f,1000.0f);<br />
<br />
glTranslatef(0.0,0.0,-7.0); <br />
}<br />
<br />
<br />
<br />
<br />
void display(void)<br />
{<br />
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); <br />
glMatrixMode(GL_MODELVIEW); <br />
glLoadIdentity();<br />
<br />
<br />
if ( data_type == 1 )<br />
{<br />
}<br />
<br />
rotate+=1.5;<br />
<br />
glPushMatrix();<br />
glColor3f(1.0,1.0,0.0);<br />
setOrthographicProjection();<br />
glLoadIdentity();<br />
renderBitmapString(10,30,(void *)font,"Display Object From File ");<br />
<br />
resetPerspectiveProjection();<br />
glPopMatrix();<br />
<br />
glFlush(); <br />
glutSwapBuffers(); <br />
}<br />
<br />
<br />
<br />
void processMenuEvents(int option) <br />
{<br />
<br />
}<br />
<br />
<br />
<br />
void create_Menu() <br />
{<br />
<br />
}<br />
<br />
<br />
<br />
int main(int argc, char **argv)<br />
{<br />
glutInit(&argc, argv); <br />
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);<br />
glutInitWindowSize(screen_width,screen_height);<br />
glutInitWindowPosition(0,0);<br />
glutCreateWindow("View Object");<br />
glutDisplayFunc(display);<br />
glutIdleFunc(display);<br />
glutReshapeFunc (resize);<br />
create_Menu();<br />
Myinit();<br />
glutMainLoop();<br />
<br />
return(0); <br />
<br />
}<br />
But, it doesn't work. Can somebody fix my code?
|
|
|
|
|
It looks like you're just using glutBitmapCharacter to display text? I'm not sure you can get shading to work on a bitmap. What were you expecting to see and what did you actually see? This would help diagnose your problem because I don't think anyone is going to take the time to compile your program and try to reproduce it.
Doing my part to piss off the religious right.
|
|
|
|
|
Tim is correct, you cannot "illuminate" or shade a bitmap text. You can convert the bitmap to a texture, use a texture font drawing routine and it will be illuminated, or you can use stroke fonts. Take a look at the font demo here: http://www.opengl.org/resources/code/samples/glut_examples/examples/examples.html[^]
or here: http://nehe.gamedev.net/lesson.asp?index=03[^]
_________________________
Asu no koto o ieba, tenjo de nezumi ga warau.
Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)
John Andrew Holmes "It is well to remember that the entire universe, with one trifling exception, is composed of others."
|
|
|
|
|
I made a control myself with an image as background
(the image is prerendered in the constructor)
when it needs to be repainted (Onpaint event)
it is repainted very slow.
so i want not to repaint the total bitmap,
but only the part that has been invalidated
g.DrawImageUnscaledAndClipped(bmp_background, e.ClipRectangle);
does not work because the origin of the bitmap is drawn at
ClipRectangle.Location
has anyone a solution for it?
|
|
|
|
|
Hi,
Graphics.DrawImage() has some 30 overloads, some of them "Draw the specified portion of the
specified Image at the specified location and with the specified size" and should solve
your problem.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
thanks
sorry for the stupid question
this is something i could have figured out for myself
|
|
|
|
|
Hello.
I have finished graphical component. It uses GDI+. I understand that I have to dispose unmanaged resources (like Pen, Brush, etc).
But one question arised. How I should dispose global resources?
I`ve decided to use global Pen because this component repaints every 100 ms (but maybe I made wrong decision).
Example of my code:
public partial class MyControl: UserControl
{
Pen myPen;
// constructor
public MyControl
{
...
myPen = new Pen(Color.Blue);
...
}
}
|
|
|
|
|
I don't know C#, but from the looks of your code sample, I don't see anything global, nor
do I see any unmanaged objects.
myPen's existence lasts as long as a MyControl object exists, right?
Am I missing something?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi,
you should call Dispose on those objects that offer it, as soon as you don't need them
anymore. Creating and disposing GDI objects may be expensive, so it is indeed wise
to avoid these operations in every OnPaint(). So you create them once "globally",
and keep them alive as long as the app lives; that is perfect. On exit, the system
will take care of them (as it always did with resources, even long before .NET came
into this world).
BTW: you don't have the right to dispose of stuff you did not create or ordered created;
this applies to the Pens class, the Brushes class, etc.
So you can replace myPen = new Pen(Color.Blue); by myPen=Pens.Blue;
and not worry about disposing of it at all.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Thanks you very much !
I'm new in C# Maybe that explains a lot.
I was just worried about way of disposing things in GDI+.
1 more question (please :
If I create the class (component) with these "global" Pens (or whatever) and after some time I don't
need this class (for example - app will change), should I implement Dispose method?
And sorry for my english
|
|
|
|
|
Hi,
your class XXX should implement Dispose() when it uses unmanged memory or other system
resources, because you either do native calls to that effect, or use objects that offer
a Dispose() themselves.
the above holds true in general; you could forget about providing Dispose() if the
class is used in one app only, where you need all objects of class XXX up to the end
of the app execution (so you would call Dispose only on exit, which is not that useful
since the system would clean up then anyway).
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Thank you again (especially for quick response)
|
|
|
|
|
Hi Guys
Is it possible to create a usercontrol with a semi-transparent background (without affecting and not relying on the parent form’s properties).
I can make the backcolor of the control transparent but I have to set the transparency key in the parent form for it to work but the form also renders out a transparent background !!!.
Here is the code i'm using inside the Usercontrol
<br />
private void DrawImageBox()<br />
{<br />
SetStyle(ControlStyles.SupportsTransparentBackGround, true);<br />
base.BackColor = Color.Transparent;<br />
<br />
if (Picture != null)<br />
{<br />
Graphics gfx = base.CreateGraphics();<br />
<br />
<br />
Bitmap bmp = new Bitmap(Picture);<br />
bmp.MakeTransparent( _transparentKey );<br />
<br />
Rectangle rec = Rectangle( 0, 0, base.Width, base.Height );<br />
<br />
gfx.DrawImage( bmp, rec, 0, 0, bmp.Width, bmp.Height, GraphicsUnit.Pixel);<br />
<br />
gfx.Dispose();<br />
}<br />
<br />
}<br />
If anyone has any ideas for how to do this I would be really grateful!
Thanks in advance!
|
|
|
|
|
Hi, the short answer to your question is no. The win32 system does not support semi-transparent controls in the way you want it. However, considering that you're UserControl is painting an image, there is an alternative way - as long as you're only painting over other graphics & not over controls (buttons, textboxes etc.). Any image you want to paint can be adjusted so that it's semi-transparent. Ditch the UserControl & paint the image from the main form by overriding the OnPaint method. Here's the code to adjust the image transparency. You'll need to enable the 'Allow unsafe code' option in the project Build properties.
private Bitmap _transImage = null;
public Form1()
{
InitializeComponent();
}
~Form1()
{
_transImage.Dispose();
}
protected override void OnLoad(EventArgs e)
{
Bitmap b = new Bitmap(@"c:\myImage.png");
_transImage = AdjustImageTransparency(b);
b.Dispose();
base.OnLoad(e);
}
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.DrawImage(_transImage, new Rectangle(40, 40, _transImage.Width, _transImage.Height));
base.OnPaint(e);
}
private Bitmap AdjustImageTransparency(Bitmap sourceImage)
{
Bitmap transImage = new Bitmap(sourceImage.Width, sourceImage.Height, PixelFormat.Format32bppArgb);
Rectangle rc = new Rectangle(Point.Empty, sourceImage.Size);
using (Graphics g = Graphics.FromImage(transImage))
g.DrawImage(sourceImage, rc);
BitmapData bd = transImage.LockBits(rc, ImageLockMode.ReadWrite, transImage.PixelFormat);
AdjustTransparency(bd, 0.5f);
transImage.UnlockBits(bd);
return transImage;
}
private unsafe void AdjustTransparency(BitmapData dataObj, float ratio)
{
int byteWidth = dataObj.Width * 4;
for (int y = 0; y < dataObj.Height; y++)
{
byte* row = (byte*)dataObj.Scan0 + dataObj.Stride * y;
for (int x = 0; x < byteWidth; x++)
{
if ((x % 4) == 3)
{
float val = (float)row[x];
val *= ratio;
val = Math.Min(Math.Max(val, 0), 255);
row[x] = (byte)val;
}
}
}
}
also, add the System.Drawing.Imaging import to your code.
Hope this helps!
Rob
"An eye for an eye only ends up making the whole world blind"
modified on Friday, April 18, 2008 3:58 PM
|
|
|
|
|
I've chatted to a few people who refuse to use GDI+ due to it's lack of "Flashy Effects" - Lighting, Tinting, Etc, Etc, Etc
So, I thought I'd ask if anyone knows how to do something... "Flashy" in GDI+...
A Fire Effect maybe? (Think Fantastic Flame Screensaver)
Get your creativity juices flowing
- Reelix
|
|
|
|
|