Advertisement
ASP_Volume2 Custom Controls/ Forms/ Menus #32691

Making a thumbnail of an image

Being optimistic, I have made a code that will resize an image, allowing the user to save the image as a thumbnail. Here's hoping I've solved problems. Even if it doesn't work for you, it should give you a small idea of how it's done.

AI

Shrnutí AI: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Zdrojový kód
original-source
Sub thumbnail(width As Integer, height As Integer, source As PictureBox, dest As PictureBox)
 'This should help me to create a thumbnail of an image.
 
 'ix and iy help to grab the pixels from the relative positions
 'of the thumbnail from the image.
 Dim ix As Single, iy As Single
 
 'x and y are just For...Next variables and xcounter/ycounter
 'are used for reference to the thumbnail.
 Dim x As Single, y As Single, xcounter As Integer, ycounter As Integer
 
 'These are a few safety precautions that you should take to
 'make sure that the code works. The ScaleMode of the
 'pictureboxes and their parents must be pixels.
 source.Parent.ScaleMode = vbPixels
 dest.Parent.ScaleMode = vbPixels
 source.ScaleMode = vbPixels
 dest.ScaleMode = vbPixels
 
 'Calculate ix and iy, which are the 'steps' from which to grab
 'pixels. Think of it as a fixed grid.
 ix = source.ScaleWidth / width
 iy = source.ScaleHeight / height
 
 'Resize the thumbnail picturebox to accomodate the new
 'thumbnail. There's a trap here; the thumbnail may not be
 'exactly the size required.
 'If you simply put dest.height = height and so on for the
 'width, you might get the extra border on the right and
 'bottom of the thumbnail.
 dest.height = source.ScaleHeight / iy
 dest.width = source.ScaleWidth / ix
 'Now we make the thumbnail.
 For y = 0 To source.ScaleHeight - 1 Step iy
 For x = 0 To source.ScaleWidth - 1 Step ix
  
  'Grab the image from the source and place it in the
  'right spot in the thumbnail picture box.
  dest.PSet (xcounter, ycounter), source.Point(x, y)
  xcounter = xcounter + 1
  
 Next
 ycounter = ycounter + 1
 xcounter = 0
 Next
 'The next line is not mandatory, except if you want the
 'thumbnail to become a picture object.
 Set dest.Picture = dest.Image
End Sub
'To save the thumbnail you would then write a line such as
'SavePicture dest.picture, "thumbnail.bmp" (or
'SavePicture dest.image), remembering that the result is a
'bitmap picture.

<HTML>
<FONT FACE="FIXEDSYS" COLOR="#BD0000">
<IMG SRC="http://www.lostsidedead-software.com/cool_logo.jpg"><BR><BR>
<b>MasterLibrary4</b><br>
Now Contains over 17,000 Lines of Code <br>
contains<br>
define MASTER_FILE_STRING_H - use the c compiler ( give dirver .c extension)<Br>
					 #define MASTERXSDK - C++/DirectX <br>
					 #define MASTERLIB - C++ <br>
					 #define MASTERIO - use the microsoft C compiler ( give driver source .c extension)<br>
					 #define MASTER_STREAM - use the C++ compiler ( .cpp extension)<br>
					 #define MASTER_STRING2 - use the C++ compiler (.cpp extension)<br>
					 #define MASTEROGL - use the C++ compiler (.cpp extension)<br>
					 #define MASASM - Master Assembly Script(.cpp extension)<br>
					 #define MASTER_LIST List Template (.cpp extension)<br>
<br>
comes with a example driver that uses masasm, to display hello world
use the right #define and include masterlibrary to use the right library aspect
in your visual c++ application.<br><br>
<b> Download </b><br><br>
<a href="http://www.lostsidedead-software.com/masterlibrary4.zip">masterlibrary4</a><br>
</FONT>
</HTML>
Původní komentáře (3)
Obnoveno z Wayback Machine