2 Replies - 1358 Views - Last Post: 15 June 2008 - 10:43 AM Rate Topic: -----

#1 jacobjordan   User is offline

  • class Me : Perfection
  • member icon

Reputation: 115
  • View blog
  • Posts: 1,499
  • Joined: 11-June 08

Resizing an image pixle by pixle

Post icon  Posted 14 June 2008 - 05:13 PM

For quite a while, I have been trying to make an algorithm to resize an image so that each pixle is resized by itself. If you don't get what I'm saying, here's an example: if I resized an image that was 16x16 by a factor of 2, each pixel in the image would now be 2 pixels wide and 2 pixels high in reality. This way if an image was sized up enough, one would be able to see the individual pixels in the original image.

I have already made an algorithm to do this, and here it is:
Public Shared Function ZoomBitmap(ByVal bmp As Bitmap, ByVal zoom As Integer) As Bitmap
		Dim rbmp As New Bitmap(bmp.Width * zoom, bmp.Height * zoom)
		Dim x As Integer
		Dim y As Integer
		Dim x2 As Integer
		Dim y2 As Integer
		Dim x2in As Integer
		Dim y2in As Integer
		Do
			Dim cl As Color
			cl = bmp.GetPixel(x, y)
			x2 = x2in
			y2 = y2in
			Do
				rbmp.SetPixel(x2, y2, cl)
				x2 += 1
				If x2 = zoom + x2in Then
					x2 = x2in
					y2 += 1
				End If
				If y2 = zoom + y2in Then
					x2in += zoom
					If x2in = bmp.Width * zoom Then
						x2in = 0
						y2in += zoom
					End If
					Exit Do
				End If
			Loop
			x += 1
			If x = bmp.Width Then
				x = 0
				y += 1
			End If
			If y = bmp.Height Then
				Exit Do
			End If
		Loop
		Return rbmp
	End Function


This algorithm does do what I just described, with one problem: it is SLOW! It takes about 10 seconds to resize a normal sized image. I know of programs that do this very thing in a fraction of the time. If you can think of any ways to improve this algorithm, or if you have and algorithm to do this efficiently, or if you know of a function already in the .NET framework that can do this, please let me know.

Is This A Good Question/Topic? 0
  • +

Replies To: Resizing an image pixle by pixle

#2 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15300
  • View blog
  • Posts: 61,364
  • Joined: 12-June 08

Re: Resizing an image pixle by pixle

Posted 15 June 2008 - 09:02 AM

Have you glanced at these?

http://www.dreaminco.../snippet638.htm

http://www.vb-helper...age_resize.html

As an aside, it would be good if your 'do loops' had a 'while/until' attached.. you know.. so infinite loops could be broken.. lol.
Was This Post Helpful? 0
  • +
  • -

#3 jacobjordan   User is offline

  • class Me : Perfection
  • member icon

Reputation: 115
  • View blog
  • Posts: 1,499
  • Joined: 11-June 08

Re: Resizing an image pixle by pixle

Posted 15 June 2008 - 10:43 AM

Yeah, i looked at the links you posted, and they don't do what i want. When they resize an image, they sort of 'smear it together' to make it look better when zoomed in on. I don't want it to do that. I want it to preserve the actual pixels in the image, so when resized up enough, it would look like a bunch of square blocks. And in reality, those blocks would be the individual pixels of the image before it was resized.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1