Reduse The Size Of An Image To 30KB-40KB

How? (By Redusing Its Quality And Size...)

Page 1 of 1

9 Replies - 14664 Views - Last Post: 09 October 2009 - 05:25 AM Rate Topic: -----

#1 Guest_NIXZ*


Reputation:

Reduse The Size Of An Image To 30KB-40KB

Post icon  Posted 08 October 2009 - 11:41 AM

That's the function i coded to reduse the quality of an image but its a complete FAILURE it doesnt even make sence
(It firstly takes a screenshot of the desktop)
	Public Function GetScreenshot() As Bitmap
		On Error Resume Next
		For Each MainScreen As Screen In Screen.AllScreens
			Dim ScreenGrab As Bitmap = New Bitmap(MainScreen.Bounds.Width, MainScreen.Bounds.Height)
			Dim GFXScreenGrab As Graphics = Graphics.FromImage(ScreenGrab)
			GFXScreenGrab.CopyFromScreen(New Point(0, 0), New Point(0, 0), New Size(MainScreen.Bounds.Width, MainScreen.Bounds.Height))
			GFXScreenGrab.Dispose()
			Dim BmpScreenGrabRedusedQuality As New Bitmap(640, 480, Imaging.PixelFormat.Format16bppRgb555)
			Dim GFXReduQualBitmap As Graphics = Graphics.FromImage(BmpScreenGrabRedusedQuality)
			GFXReduQualBitmap.InterpolationMode = Drawing2D.InterpolationMode.Bilinear
			GFXReduQualBitmap.DrawImage(ScreenGrab, New Rectangle(0, 0, BmpScreenGrabRedusedQuality.Width, BmpScreenGrabRedusedQuality.Height), New Rectangle(0, 0, ScreenGrab.Width, ScreenGrab.Height), GraphicsUnit.Pixel)
			GFXReduQualBitmap.Dispose()
			Return BmpScreenGrabRedusedQuality
		Next
	End Function


How can i achieve a ( 800X600 / 256 Colours ) Image to have the lowest file size possible?
Yeah 70KB --> 30KB makes a HUGE! difference. 30KB IS PERFECT!

This post has been edited by NIXZ: 09 October 2009 - 03:55 AM


Is This A Good Question/Topic? 0

Replies To: Reduse The Size Of An Image To 30KB-40KB

#2 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2271
  • View blog
  • Posts: 9,499
  • Joined: 29-May 08

Re: Reduse The Size Of An Image To 30KB-40KB

Posted 08 October 2009 - 12:37 PM

Shrink its dimensions further, reduce color count
Was This Post Helpful? 0
  • +
  • -

#3 Guest_NIXZ*


Reputation:

Re: Reduse The Size Of An Image To 30KB-40KB

Posted 08 October 2009 - 12:54 PM

View PostAdamSpeight2008, on 8 Oct, 2009 - 11:37 AM, said:

Shrink its dimensions further,


It Has to Be 800x600 or 640x480

View PostAdamSpeight2008, on 8 Oct, 2009 - 11:37 AM, said:

reduce color count


How? Isnt This The Lowest That It Can Go?:
Imaging.PixelFormat.Format16bppRgb555
Anything lower doesnt work the bitmap returns as a black image.
Was This Post Helpful? 0

#4 crepitus  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 85
  • View blog
  • Posts: 383
  • Joined: 08-September 09

Re: Reduse The Size Of An Image To 30KB-40KB

Posted 08 October 2009 - 03:34 PM

View PostNIXZ, on 8 Oct, 2009 - 11:54 AM, said:

How? Isnt This The Lowest That It Can Go?:
Imaging.PixelFormat.Format16bppRgb555
Anything lower doesnt work the bitmap returns as a black image.


Using that format doesn't make sense.
GIF is an indexed image format. This means that each pixel stores a number, the number is the index of the colour in a palette.
compare it to...
Format16bppRgb555 - this is not indexed, each pixel uses 5 bits for Red, 5 bits for Green and 5 bits for Blue, there is no palette.

What does your code that actually saves the file look like?
Was This Post Helpful? 0
  • +
  • -

#5 motcom  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 290
  • View blog
  • Posts: 1,371
  • Joined: 16-June 08

Re: Reduse The Size Of An Image To 30KB-40KB

Posted 09 October 2009 - 12:24 AM

Just something simple,

Try and zip it??
Was This Post Helpful? 0
  • +
  • -

#6 crepitus  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 85
  • View blog
  • Posts: 383
  • Joined: 08-September 09

Re: Reduse The Size Of An Image To 30KB-40KB

Posted 09 October 2009 - 02:28 AM

It's already compressed with Gif, zip isn't going to get it any further.

Gif isn't lossy, so you can't set a Quality setting as you can for jpg.

If the image dimensions can't be reduced further, then reducing the number of colors in the palette is the only way, I think. Quantisation will allow decent colours to be selected.
Was This Post Helpful? 0
  • +
  • -

#7 motcom  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 290
  • View blog
  • Posts: 1,371
  • Joined: 16-June 08

Re: Reduse The Size Of An Image To 30KB-40KB

Posted 09 October 2009 - 02:38 AM

one learns every day... :rolleyes:

but is 70k and 30-40k not alomost identical?

I mean when sending files over the net it should not pose a problem?

I live in Africa and our net is extremely slow but sending 70k is not a problem...
Was This Post Helpful? 0
  • +
  • -

#8 crepitus  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 85
  • View blog
  • Posts: 383
  • Joined: 08-September 09

Re: Reduse The Size Of An Image To 30KB-40KB

Posted 09 October 2009 - 03:31 AM

Yeah, making do with whatever size is generated would make sense. If you keep reducing the size and colours you end up with something that you can't read.

If I had to do this myself, I would investigate Floyd-Steinberg dithering and quantization. Quantization will select the colours for the smaller palette. Dithering will reduce the complexity of the image, so Gif will be able to compress it more. It's very complicated. You would need to use fast pixel access, and a convolution filter for the dithering. I've not got the time atm.

Maybe there's a library out there that can do this stuff...
Was This Post Helpful? 0
  • +
  • -

#9 Guest_NIXZ*


Reputation:

Re: Reduse The Size Of An Image To 30KB-40KB

Posted 09 October 2009 - 03:51 AM

How can i achieve a ( 800X600 / 256 Colours ) Image to have the lowest file size possible?
Yeah 70KB --> 30KB makes a HUGE! difference. 30KB IS PERFECT!

This post has been edited by NIXZ: 09 October 2009 - 03:55 AM

Was This Post Helpful? 0

#10 crepitus  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 85
  • View blog
  • Posts: 383
  • Joined: 08-September 09

Re: Reduse The Size Of An Image To 30KB-40KB

Posted 09 October 2009 - 05:25 AM

View PostNIXZ, on 9 Oct, 2009 - 02:51 AM, said:

How can i achieve a ( 800X600 / 256 Colours ) Image to have the lowest file size possible?


Imports System.Drawing.Imaging

Public Class Form1

	Public Function ScreenShot() As Bitmap
		Dim shot As New Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height)
		Using g As Graphics = Graphics.FromImage(shot)
			g.CopyFromScreen(New Point, New Point, shot.Size)
		End Using
		Return shot
	End Function

	Public Function ResizeImage(ByVal img As Bitmap, ByVal width As Integer, ByVal height As Integer) As Bitmap
		Dim resized As New Bitmap(width, height)
		Using g As Graphics = Graphics.FromImage(resized)
			g.DrawImage(img, resized.GetBounds(GraphicsUnit.Pixel))
		End Using
		Return resized
	End Function

	Public Sub SaveScreenshot(ByVal imageSize As Size)
		' Take a screenshot and re-draw it into a bitmap of the size we want.
		Dim sizedShot As Bitmap = ResizeImage(ScreenShot, imageSize.Width, imageSize.Height)
		sizedShot.Save(My.Computer.FileSystem.SpecialDirectories.MyPictures & "\test.gif", ImageFormat.Gif)
		sizedShot.Dispose()
	End Sub

	Private Sub Form1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click
		SaveScreenshot(New Size(800, 600))
	End Sub
End Class


The image size will depend on what is visible in the screenshot - Gif can compress some images better than others.
The image produced is 800x600 Gif with 256 colours in the pallete.

If I take the completed gif file and try to re-save it with Paint.Net, I can't get ANY improvement in the file size using dithering.
However, if I save the re-sized screenshot as Png, and re-save it with paint.Net as a Gif then dithering allows me to drop the file size further (<30K is possible)
Dithering can do it then, but it's not built in and it is very complicated. Look for a library.

This post has been edited by crepitus: 09 October 2009 - 05:30 AM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1