Resumé

Distort Images with GDIplus (solution)

Cristian Merighi () 5.00

Distort an image, using GDI+ .Net classes, by giving 4 destination points. A possible solution.
This article is obsolete. Some functionalities might not work anymore. Comments are disabled.

This article prosecutes the discussion started about a week ago.

The problem has been solved using, as the good old Euclid would say, Compass and straightedge.
(For a geometry based outline please refer to this article).

As usual it is possible to test, inserting values as you prefer, the distorting method:

test img
top-left corner: ,
top-right corner: ,
bottom-left corner: ,
bottom-right corner: ,
 
 

In case of positive and fairly large feedback, I'll set a WebService or an alternative way of distribution.
If asked, I'll write a deeper tractation. Just let me know...

zip file « download code

Take care. Bye.

Feedbacks

  • Re: Distort Images with GDIplus (solution)

    spart3b Saturday, September 30, 2006 5.00

    Excellent! Now where is the downloads section!? ;) All seriousness though, I'd love to see how you did this.

  • Re: Distort Images with GDIplus (solution)

    CMerighi Sunday, October 1, 2006 0.00

    Code has been added, as requested... (Please refer about bugs or malfunctions)

  • Re: Distort Images with GDIplus (solution)

    spart3b Tuesday, October 3, 2006 0.00

    Very interesting solution, I grasp it, but there are a lot of missing pieces code-wise. Any chance on getting the help helper functions used in Distort posted? (GetAngularCoefficient, GetIntersection, MakeTransparent)

  • Re: Distort Images with GDIplus (solution)

    CMerighi Tuesday, October 3, 2006 0.00

    They are included in the .cs file (see the "MATH UTIL" #region) and they're accompanied by relevant comment... Except for "MakeTransparent": that's a System.Drawing.Bitmap class method. If you need more comments between the rows (in the Distort method body), I promise I'll add some as soon as I can (always daily job permitting)!

  • Re: Distort Images with GDIplus (solution)

    spart3b Friday, December 22, 2006 0.00

    Hey Cristian - getting back into this project and I was wondering if I could get a copy of the test app above? I had to tweak a couple things in the Image class and I'm not getting the desired results - however your test above works beautifully. Let me know! Thanks!

  • Re: Distort Images with GDIplus (solution)

    CMerighi Friday, December 22, 2006 0.00

    I'm starting to receive several requests about my GDI+ component, that makes me really happy! I've added to the zip file the exact <b>ashx</b> I use to flush the distorted sample image (hope that would help). I cannot expose my Pacem.Drawing.Image class: there are other interesting features (<a href="http://www.pacem.it/en-US/31/Pacem-XC-images-gdiplus.aspx">see here</a>) I intend to keep hidden. I'm also working to a new version of my site which will permit to acquire that and other Libraries, but that will be available only in the early months of 2007...

  • Re: Distort Images with GDIplus (solution)

    spart3b Saturday, December 23, 2006 0.00

    Thanks for the quick response! Glad to hear your getting some interest, it's good work. One thing though, I mentioned above that something is a bit off with my implementation. I modified the distort function to accept a bitmap object as input (the image to be distorted) and to return a bitmap objected (the distorted image). However I am getting some crazy looking results. Any way you could make an override on the Distort class that took that additional input and returned the distorted Bitmap object? When you have time of course! Thanks in advance!

  • Re: Distort Images with GDIplus (solution)

    spart3b Saturday, December 23, 2006 0.00

    Ah hah! You got me with the A, B, D, C point parameter situation. Working now, thanks!

  • Re: Distort Images with GDIplus (solution)

    CMerighi Saturday, December 23, 2006 0.00

    ...you're welcome :)

  • Re: Distort Images with GDIplus (solution)

    Ribonix Saturday, February 10, 2007 0.00

    ho inserito i tuoi sorgenti e l'immagine su un server ma non riesco ad eseguirli. Non riesci a fare qualcosa di simile anche in VB anzichè in C sempre su piattaforma asp.net. Grazie Grazie.

  • Re: Distort Images with GDIplus (solution)

    CMerighi Sunday, February 11, 2007 0.00

    Ciao Robonix, In realtà non è previsto che i file scaricabili in questo articolo funzionino così come sono: il metodo "Distort", ad esempio, agisce su un oggetto System.Drawing.Bitmap dichiarato altrove nella classe Pacem.Drawing.Image. Lo scopo dell'articolo è quello di riportare esaustivamente un algoritmo in grado di distorcere un'immagine dati quattro punti qualsiasi. Sta poi al singolo sviluppatore accorpare tale funzionalità al proprio progetto secondo le modalità che preferisce. Il codice è in sintassi C# 2.0 ma ci sono sul web tools in grado di tradurre il tutto in un più familiare VB (<a href="http://www.developerfusion.co.uk/utilities/convertcsharptovb.aspx" target="_blank">esempio</a>). Se possiedi un po' di dimestichezza cogli oggetti GDI+ non ti dovrebbe risultare complicato assemblare del codice funzionante a partire da quello provvisto. Fammi sapere...

  • Re: Distort Images with GDIplus (solution)

    Ribonix Tuesday, February 13, 2007 0.00

    Scusa la mia ignoranza. E' da poco che ho iniziato ad utilizzare l'ASP.NET. Ho qualche infarinatura di C# ma proprio non riesco a capire come creare del codice funzionante con il materiale che hai gentilmente fornito. Grazie e scusa del disturbo.

  • Re: Distort Images with GDIplus (solution)

    CMerighi Wednesday, February 14, 2007 0.00

    Mmmhh... vedo cosa posso fare: compatibilmente coi miei impegni (e coi problemi di connettività che al momento mi affliggono!) conto di approntare una solution completa in VB.Net funzionante. Spero di farti cosa gradita...

  • Re: Distort Images with GDIplus (solution)

    Ribonix Wednesday, February 14, 2007 0.00

    Grazie mille.

  • Re: Distort Images with GDIplus (solution)

    CMerighi Friday, February 16, 2007 0.00

    ...come promesso. Scarica il progetto VB.Net da <a href="http://www.pacem.it/CMerighi/Posts/40,it-IT/Distorsione_delle_Immagini_-_Progetto_in_VB.Net.aspx">qui</a>.

  • Re: Distort Images with GDIplus (solution)

    Ribonix Sunday, February 18, 2007 5.00

    Fantastico!!! Sarà stata forse la fretta di far funzionare il tutto ma all'inizio ho avuto qualche difficoltà a far funzionare i tuoi nuovi sorgenti. Non avevo capito che tutti i sorgenti e la directory con il file .VB dovevano risiedere nella root del sito. Li avevo messi tutti in una directory della root del sito (volutamente chiamata PACEM) tranne il file web.config che ho messo direttamente in root. Ovviamente ho ancora molto da imparare!!! Funziona tutto. Ora il mio passo successivo è quello di far coesistere più immagini distorte nella stessa immagine finale. Immagina ad esempio un corridoio che si estende all'infinito con immagini laterali... Ti faccio i miei complimenti e ti ringrazio per la disponibilità e, se me lo consenti, ti auguro tante cose belle nella vita! Ciao

  • Re: Distort Images with GDIplus (solution)

    CMerighi Sunday, February 18, 2007 0.00

    ...accetto l'augurio eccome! ;)

  • Re: Distort Images with GDIplus (solution)

    Ribonix Thursday, April 5, 2007 0.00

    Scusami... ti stresso ancora. Ho provato a procedere da solo tutto questo tempo ma come puoi vedere sono ancora qui. Non riesco a fare in modo che più immagini distorte coesistano in un'unica immagine. Probabilmente non riesco a comprendere appieno le istruzioni del programma. Ciao, grazie e Buona Pasqua.

  • Re: Distort Images with GDIplus (solution)

    CMerighi Friday, April 6, 2007 0.00

    In realtà nel codice che ho reso disponibile non ci sono metodi che permettano di fare tutto ciò. Quello che chiedi però si può "tranquillamente" fare, con le seguenti modalità: dovresti costruirti gli <i>n</i> oggetti Bitmap (tanti quante sono le immagini da distorcere ed assemblare), più un <i>n+1</i>-esimo dentro il quale disegnare le altre immagini ognuna nella posizione desiderata. Fa' riferimento agli oggetti <i>System.Drawing.Graphics</i> (ed in particolar modo al metodo DrawImage) e <i>System.Drawing.Bitmap</i>. Forse ti può risultare utile <a href="http://www.pacem.it/CMerighi/Posts/15,it-IT/GDIplus_e_C%23_rating.aspx">questo articolo</a>, nel quale illustro come sovrapporre più immagini usando le API GDI+ del .Net Framework. Spero ti sia utile.

  • Re: Distort Images with GDIplus (solution)

    Ribonix Thursday, May 24, 2007 0.00

    Ciao, eccomi ancora qui. Come vedi ho cercato di non recarti ulteriore fastidio e di proseguire "tranquillamente" da solo. Ma nonostante siano passati 2 mesi non riesco ad andare avanti. Mi reputo abbastanza in grado di inserire più immagini all'interno di un'altra immagine. Ma quando si tratta di inserire più immagini distorte all'interno di un'immagine finale usando i tuoi sorgenti ho ancora grosse difficoltà. E' per questo che ti chiedo se puoi pubblicare del codice che mostri come applicare questa possibilità. Grazie ancora e scusa x il disturbo.

  • Re: Distort Images with GDIplus (solution)

    CMerighi Friday, May 25, 2007 0.00

    ...vedo di fare il possibile, anche se questo non è il periodo migliore: sono piuttosto preso e - come puoi notare - non riesco nemmeno a scrivere nuovi articoli sul blog! Spero di riuscire ad accontentarti quanto prima

  • Re: Distort Images with GDIplus (solution)

    Ribonix Friday, May 25, 2007 0.00

    Non c'è fretta. Sei stato gentilissimo. Ciao

  • Re: Distort Images with GDIplus (solution)

    Carlos Saturday, February 23, 2008 5.00

    Any chance to have a Visual Basic 6 sample project? Thank you in advance.

  • Re: Distort Images with GDIplus (solution)

    CMerighi Sunday, February 24, 2008 0.00

    Sorry Carlos, a VB.Net (8) version for this project and also a correction to the algorithms have already been posted on this blog: - <a href="http://www.pacem.it/CMerighi/Posts/40,en-US/VB.Net_Project_for_Images_Distortion.aspx">www.pacem.it/.../VB.Net_Project_for_Images_Distortion.aspx</a> - <a href="http://www.pacem.it/CMerighi/Posts/61,en-US/Image_Distortion_Enhancements.aspx">www.pacem.it/.../Image_Distortion_Enhancements.aspx</a> but I unfortunately do not manage older technologies like VB6...

  • Re: Distort Images with GDIplus (solution)

    Carlos Tuesday, February 26, 2008 0.00

    Thank you CMerighi.

  • Re: Distort Images with GDIplus (solution)

    Matt Saturday, August 30, 2008 5.00

    Great article! One question though, Luke talks about his image being a transparent png but in the sample it's a JPG and the background color is black. I've tried changing the ImageFormat and the content-type to png with no luck. Any suggestiosn?

  • Re: Distort Images with GDIplus (solution)

    CMerighi Sunday, August 31, 2008 0.00

    Hi Matt, please check if <a href="http://www.pacem.it/CMerighi/Posts/61,en-US/Image_Distortion_Enhancements.aspx">this</a> article and relevant code result useful for you.

  • Re: Distort Images with GDIplus (solution)

    Daniel Ribeiro Saturday, February 7, 2009 5.00

    Hi CMerighi, nice work! I was using this code for a while and it's very handy, but I'm having some performance problems and I'm looking for an enhanced version of this code, some that can use the WPF on .NET 2008 or use hardware acceleration to do image Distortion Faster. Is any chance to you discuss some changes like that? Thanks a lot!

feedback
 

Syndicate

Author

Cristian Merighi facebook twitter google+ youtube

Latest articles

Top rated

Archive

Where am I?

Author

Cristian Merighi facebook twitter google+ youtube

I'm now reading

Feeds