elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: (TUTORIAL) Aprende a emular Sentinel Dongle By Yapis


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP) (Moderador: kub0x)
| | | |-+  Ayuda en c# con poner imagen sobre imagen
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Ayuda en c# con poner imagen sobre imagen  (Leído 7,435 veces)
purocuque

Desconectado Desconectado

Mensajes: 5


Ver Perfil
Ayuda en c# con poner imagen sobre imagen
« en: 28 Abril 2015, 01:59 am »

Buen día quiero empezar un programa en c# orientado a objetos en el que me permita seleccionar una imagen e insertarla dentro de otra que haya abierto anteriormenete que la imagen que abra me permita cambiar tamaño
Dejaré un ejemplo por aca. Básicamente lo que necesito es insertar una imagen sobre otra :-X


En línea

USLO

Desconectado Desconectado

Mensajes: 175

Programador(C#,Vb.net,Asp.Net,JavaAndroid)


Ver Perfil
Re: Ayuda en c# con poner imagen sobre imagen
« Respuesta #1 en: 30 Abril 2015, 13:12 pm »


Ni tan siquiera te has molestado en preguntar lo que necesitas.
Y quieres que te lo hagamos o que?

Voy a abrir un tema nuevo(Necesito dinero).Sin preguntas a ver si cae del cielo.

En fin.Hay que molestarse un poco mas en formular preguntas y mostrar interés en resolver sus propias dudas.

Ahora si sigues interesado formula tu pregunta?
Un saludo.


En línea

Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.788



Ver Perfil
Re: Ayuda en c# con poner imagen sobre imagen
« Respuesta #2 en: 30 Abril 2015, 18:34 pm »

En un principio yo también veo mal ofrecer ayuda a quien lo pide todo hecho sin mostrar código alguno, pero me he dado cuenta de que un "ejercicio" o utilidad cómo esta me faltaba en mi librería personal de códigos y me ha llamado la atención el desarrollar este tipo de utilidad para un uso genérico, ya que lo hago pues lo comparto.

Imagen trasera e imagen delantera
   

Superposición (opaca)


Código fuente
Código
  1.    ''' <remarks>
  2.    ''' *****************************************************************
  3.    ''' Snippet Title: Overlay Images
  4.    ''' Code's author: Elektro
  5.    ''' Date Modified: 30-April-2015
  6.    ''' *****************************************************************
  7.    ''' </remarks>
  8.    ''' <summary>
  9.    ''' Overlay an image over a background image.
  10.    ''' </summary>
  11.    ''' <param name="backImage">The background image.</param>
  12.    ''' <param name="topImage">The topmost image.</param>
  13.    ''' <param name="topPosX">An optional adjustment of the top image's "X" position.</param>
  14.    ''' <param name="topPosY">An optional adjustment of the top image's "Y" position.</param>
  15.    ''' <returns>The overlayed image.</returns>
  16.    ''' <exception cref="ArgumentNullException">backImage or topImage</exception>
  17.    ''' <exception cref="ArgumentException">Image bounds are greater than background image.;topImage</exception>
  18.    Public Shared Function OverlayImages(ByVal backImage As Image,
  19.                                         ByVal topImage As Image,
  20.                                         Optional ByVal topPosX As Integer = 0,
  21.                                         Optional ByVal topPosY As Integer = 0) As Image
  22.  
  23.        If backImage Is Nothing Then
  24.            Throw New ArgumentNullException(paramName:="backImage")
  25.  
  26.        ElseIf topImage Is Nothing Then
  27.            Throw New ArgumentNullException(paramName:="topImage")
  28.  
  29.        ElseIf (topImage.Width > backImage.Width) OrElse
  30.               (topImage.Height > backImage.Height) Then
  31.            Throw New ArgumentException(message:="Image bounds are greater than background image.", paramName:="topImage")
  32.  
  33.        Else
  34.            topPosX += CInt((backImage.Width / 2) - (topImage.Width / 2))
  35.            topPosY += CInt((backImage.Height / 2) - (topImage.Height / 2))
  36.  
  37.            Dim bmp As New Bitmap(backImage.Width, backImage.Height)
  38.  
  39.            Using canvas As Graphics = Graphics.FromImage(bmp)
  40.  
  41.                canvas.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
  42.  
  43.                canvas.DrawImage(image:=backImage,
  44.                                 destRect:=New Rectangle(0, 0, bmp.Width, bmp.Height),
  45.                                 srcRect:=New Rectangle(0, 0, bmp.Width, bmp.Height),
  46.                                 srcUnit:=GraphicsUnit.Pixel)
  47.  
  48.                canvas.DrawImage(image:=topImage,
  49.                                 destRect:=New Rectangle(topPosX, topPosY, topImage.Width, topImage.Height),
  50.                                 srcRect:=New Rectangle(0, 0, topImage.Width, topImage.Height),
  51.                                 srcUnit:=GraphicsUnit.Pixel)
  52.  
  53.                canvas.Save()
  54.  
  55.            End Using
  56.  
  57.            Return bmp
  58.  
  59.        End If
  60.  
  61.    End Function

Traducción online a C#
Código
  1. /// <remarks>
  2. /// *****************************************************************
  3. /// Snippet Title: Overlay Images
  4. /// Code's author: Elektro
  5. /// Date Modified: 30-April-2015
  6. /// *****************************************************************
  7. /// </remarks>
  8. /// <summary>
  9. /// Overlay an image over a background image.
  10. /// </summary>
  11. /// <param name="backImage">The background image.</param>
  12. /// <param name="topImage">The topmost image.</param>
  13. /// <param name="topPosX">An optional adjustment of the top image's "X" position.</param>
  14. /// <param name="topPosY">An optional adjustment of the top image's "Y" position.</param>
  15. /// <returns>The overlayed image.</returns>
  16. /// <exception cref="ArgumentNullException">backImage or topImage</exception>
  17. /// <exception cref="ArgumentException">Image bounds are greater than background image.;topImage</exception>
  18. public static Image OverlayImages(Image backImage, Image topImage, int topPosX = 0, int topPosY = 0)
  19. {
  20.  
  21.        if (backImage == null) {
  22. throw new ArgumentNullException(paramName: "backImage");
  23.  
  24. } else if (topImage == null) {
  25. throw new ArgumentNullException(paramName: "topImage");
  26.  
  27. } else if ((topImage.Width > backImage.Width) || (topImage.Height > backImage.Height)) {
  28. throw new ArgumentException("Image bounds are greater than background image.", "topImage");
  29.  
  30. } else {
  31. topPosX += Convert.ToInt32((backImage.Width / 2) - (topImage.Width / 2));
  32. topPosY += Convert.ToInt32((backImage.Height / 2) - (topImage.Height / 2));
  33.  
  34. Bitmap bmp = new Bitmap(backImage.Width, backImage.Height);
  35.  
  36. using (Graphics canvas = Graphics.FromImage(bmp)) {
  37. canvas.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic;
  38. canvas.DrawImage(image: backImage, destRect: new Rectangle(0, 0, bmp.Width, bmp.Height), srcRect: new Rectangle(0, 0, bmp.Width, bmp.Height), srcUnit: GraphicsUnit.Pixel);
  39. canvas.DrawImage(image: topImage, destRect: new Rectangle(topPosX, topPosY, topImage.Width, topImage.Height), srcRect: new Rectangle(0, 0, topImage.Width, topImage.Height), srcUnit: GraphicsUnit.Pixel);
  40.  
  41. canvas.Save();
  42. }
  43. return bmp;
  44. }
  45. }
  46.  
  47. //=======================================================
  48. //Service provided by Telerik (www.telerik.com)
  49. //=======================================================

Modo de empleo (el mismo que he usado para generar el ejemplo de superposición de arriba)
Código
  1. Dim backImg As Image = Image.FromFile("C:\back.jpg")
  2. Dim topImg As Image = Image.FromFile("C:\top.png")
  3. Dim overlay As Image = OverlayImages(backImg, topImg, topPosX:=+5, topPosY:=-15)
  4. overlay.Save("C:\Overlay.jpg", Imaging.ImageFormat.Jpeg)
  5. Process.Start("C:\Overlay.jpg")

Saludos
« Última modificación: 30 Abril 2015, 19:58 pm por Eleкtro » En línea

USLO

Desconectado Desconectado

Mensajes: 175

Programador(C#,Vb.net,Asp.Net,JavaAndroid)


Ver Perfil
Re: Ayuda en c# con poner imagen sobre imagen
« Respuesta #3 en: 4 Mayo 2015, 09:07 am »

Que bueno eres Eleкtro.

Ya que te lo dan mascado, trata de entenderlo(Purocuque).
Si no, no aprendes.

Un saludo.
En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
poner avatar o imagen « 1 2 »
Sugerencias y dudas sobre el Foro
ZID_MIZHAR_ZETA 15 8,938 Último mensaje 26 Agosto 2004, 22:49 pm
por Ðevastador
Poner una imagen en el peril
Sugerencias y dudas sobre el Foro
hernanlp83 2 2,338 Último mensaje 1 Diciembre 2004, 01:55 am
por hernanlp83
poner temporizador a una imagen
Diseño Gráfico
julio2 5 2,206 Último mensaje 19 Mayo 2005, 19:42 pm
por Morris
poner scrollbar a una imagen
Programación Visual Basic
LixKeÜ 0 1,107 Último mensaje 3 Marzo 2006, 23:32 pm
por LixKeÜ
MOVIDO: Ayuda en c# con poner imagen sobre imagen
Programación C/C++
Eternal Idol 0 1,500 Último mensaje 30 Abril 2015, 12:23 pm
por Eternal Idol
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines