peterned
asked on
Splitting gif/jpg file into pieces
Hi,
I need to split an image file(gif or jpg) into pieces.
If there is a file like img.gif, I want to split it into files named img1.gif...img4.gif, all having the same image size = img.gif_width/2 x img.gif_heigth/2
The input file extension should be preserved in the pieces.
thanks
I need to split an image file(gif or jpg) into pieces.
If there is a file like img.gif, I want to split it into files named img1.gif...img4.gif, all having the same image size = img.gif_width/2 x img.gif_heigth/2
The input file extension should be preserved in the pieces.
thanks
To save as gif format you need too money.
To save as jpg there is a free dll you could use.
I have to search the url.
To save as jpg there is a free dll you could use.
I have to search the url.
ASKER
thanx, i'll see these
using your examples in my other question, I was able to split .jpg and .gif into pieces and save them in the same format.
The Opera browser displays the pieces just fine, but IE, Netscape, Photoshop etc can't - this means (as I think) the image data is OK but something in the file (which Opera ignores) should be different. If I open the input image with hex editor(ultraedit), it starts with
ÿØÿà JFIF
Saved pieces start with
BMv~
using your examples in my other question, I was able to split .jpg and .gif into pieces and save them in the same format.
The Opera browser displays the pieces just fine, but IE, Netscape, Photoshop etc can't - this means (as I think) the image data is OK but something in the file (which Opera ignores) should be different. If I open the input image with hex editor(ultraedit), it starts with
ÿØÿà JFIF
Saved pieces start with
BMv~
Just in case it hasn't been mentioned earlier...
look at the PicClip control. You could divvy up the picture any way you want (in rectangles), and save the resultant pieces as separate images. Or use them as they are created - up to you.
look at the PicClip control. You could divvy up the picture any way you want (in rectangles), and save the resultant pieces as separate images. Or use them as they are created - up to you.
peterned:
I used that from vbaccelerator without any problem.
I am still not able to resolve gif matter but for jpg, you could try this:
' Picture needs to set scalemode to pixels as a warranty.
Option Explicit
Private Type imgdes ' Image descriptor
ibuff As Long
stx As Long
sty As Long
endx As Long
endy As Long
buffwidth As Long
palette As Long
colors As Long
imgtype As Long
bmh As Long
hBitmap As Long
End Type
' Victor functions
Private Declare Function allocimage Lib "VIC32.DLL" (image As imgdes, ByVal wid As Long, ByVal leng As Long, ByVal BPPixel As Long) As Long
Private Declare Sub freeimage Lib "VIC32.DLL" (image As imgdes)
Private Declare Function rainbowpalette Lib "VIC32.DLL" (image As imgdes) As Long
Private Declare Function savegif Lib "VIC32.DLL" (ByVal Fname As String, srcimg As imgdes) As Long
Private Declare Function savejpg Lib "VIC32.DLL" (ByVal Fname As String, srcimg As imgdes, ByVal quality As Long) As Long
Private Declare Function updatebitmapcolortable Lib "VIC32.DLL" (image As imgdes) As Long
' Windows functions
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
' VB function to save a picture box to JPEG and GIF files
Private Sub savePicBox()
Dim rcode, dummy As Long
Dim tempimage As imgdes
Dim hMemDC As Long
Dim hOldBitmap As Long
Dim width, height, vbitcount As Long
Const SRCCOPY = &HCC0020
'' Save contents of Picture1, picture box control to a JPEG file
'vbitcount = 24 ' Use 24-bit for JPEG, use 8-bit for GIF
'width = Picture1.ScaleWidth
'height = Picture1.ScaleHeight
'hMemDC = CreateCompatibleDC(Picture 1.hdc)
'
'' Allocate the buffer to hold the image
'rcode = allocimage(tempimage, width, height, vbitcount)
'If (rcode = 0) Then
' ' Select our image buffer into the memory device context
' ' all subsequent operations on the device context alter
' ' the pixels in the image buffer.
' hOldBitmap = SelectObject(hMemDC, tempimage.hBitmap)
'
' ' The bitblt copies pixel data from the picture box into the image buffer
' dummy = BitBlt(hMemDC, 0, 0, width, height, Picture1.hdc, 0, 0, SRCCOPY)
' ' Save the image
' rcode = savejpg("c:\newimage.jpg", tempimage, 75)
'End If
'
' ' We're done, so release the device context and free the image buffer
'hOldBitmap = SelectObject(hMemDC, hOldBitmap)
'dummy = DeleteDC(hMemDC)
'freeimage tempimage
' Save contents of Picture1, picture box control to a GIF file
' Same procedure as for the JPEG, but we allocate an 8-bit buffer,
' create a rainbow palette, and call savegif.
vbitcount = 8
width = Picture1.width
height = Picture1.height
hMemDC = CreateCompatibleDC(Picture 1.hdc)
rcode = allocimage(tempimage, width, height, vbitcount)
If (rcode = 0) Then
dummy = rainbowpalette(tempimage)
dummy = updatebitmapcolortable(tem pimage)
hOldBitmap = SelectObject(hMemDC, tempimage.hBitmap)
dummy = BitBlt(hMemDC, 0, 0, width, height, Picture1.hdc, 0, 0, SRCCOPY)
rcode = savegif("c:\newimage.gif", tempimage)
End If
hOldBitmap = SelectObject(hMemDC, hOldBitmap)
dummy = DeleteDC(hMemDC)
freeimage tempimage
End Sub
Private Sub Command1_Click()
savePicBox
End Sub
mcoop, that idea was already presented in other task regarding peterned's problem.
I used that from vbaccelerator without any problem.
I am still not able to resolve gif matter but for jpg, you could try this:
' Picture needs to set scalemode to pixels as a warranty.
Option Explicit
Private Type imgdes ' Image descriptor
ibuff As Long
stx As Long
sty As Long
endx As Long
endy As Long
buffwidth As Long
palette As Long
colors As Long
imgtype As Long
bmh As Long
hBitmap As Long
End Type
' Victor functions
Private Declare Function allocimage Lib "VIC32.DLL" (image As imgdes, ByVal wid As Long, ByVal leng As Long, ByVal BPPixel As Long) As Long
Private Declare Sub freeimage Lib "VIC32.DLL" (image As imgdes)
Private Declare Function rainbowpalette Lib "VIC32.DLL" (image As imgdes) As Long
Private Declare Function savegif Lib "VIC32.DLL" (ByVal Fname As String, srcimg As imgdes) As Long
Private Declare Function savejpg Lib "VIC32.DLL" (ByVal Fname As String, srcimg As imgdes, ByVal quality As Long) As Long
Private Declare Function updatebitmapcolortable Lib "VIC32.DLL" (image As imgdes) As Long
' Windows functions
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
' VB function to save a picture box to JPEG and GIF files
Private Sub savePicBox()
Dim rcode, dummy As Long
Dim tempimage As imgdes
Dim hMemDC As Long
Dim hOldBitmap As Long
Dim width, height, vbitcount As Long
Const SRCCOPY = &HCC0020
'' Save contents of Picture1, picture box control to a JPEG file
'vbitcount = 24 ' Use 24-bit for JPEG, use 8-bit for GIF
'width = Picture1.ScaleWidth
'height = Picture1.ScaleHeight
'hMemDC = CreateCompatibleDC(Picture
'
'' Allocate the buffer to hold the image
'rcode = allocimage(tempimage, width, height, vbitcount)
'If (rcode = 0) Then
' ' Select our image buffer into the memory device context
' ' all subsequent operations on the device context alter
' ' the pixels in the image buffer.
' hOldBitmap = SelectObject(hMemDC, tempimage.hBitmap)
'
' ' The bitblt copies pixel data from the picture box into the image buffer
' dummy = BitBlt(hMemDC, 0, 0, width, height, Picture1.hdc, 0, 0, SRCCOPY)
' ' Save the image
' rcode = savejpg("c:\newimage.jpg",
'End If
'
' ' We're done, so release the device context and free the image buffer
'hOldBitmap = SelectObject(hMemDC, hOldBitmap)
'dummy = DeleteDC(hMemDC)
'freeimage tempimage
' Save contents of Picture1, picture box control to a GIF file
' Same procedure as for the JPEG, but we allocate an 8-bit buffer,
' create a rainbow palette, and call savegif.
vbitcount = 8
width = Picture1.width
height = Picture1.height
hMemDC = CreateCompatibleDC(Picture
rcode = allocimage(tempimage, width, height, vbitcount)
If (rcode = 0) Then
dummy = rainbowpalette(tempimage)
dummy = updatebitmapcolortable(tem
hOldBitmap = SelectObject(hMemDC, tempimage.hBitmap)
dummy = BitBlt(hMemDC, 0, 0, width, height, Picture1.hdc, 0, 0, SRCCOPY)
rcode = savegif("c:\newimage.gif",
End If
hOldBitmap = SelectObject(hMemDC, hOldBitmap)
dummy = DeleteDC(hMemDC)
freeimage tempimage
End Sub
Private Sub Command1_Click()
savePicBox
End Sub
mcoop, that idea was already presented in other task regarding peterned's problem.
oops, remove the comment sign if not you could not save the jpg format.
ASKER
Richie,
it didn't work. When I tried to register vic32.dll, an error like 'DLLRegisterServer entry point not found' was displayed (i run w2k pro sp1).
I tried to save gif as gif, bmp as gif/jpg and jpg as jpg, but in all cases the saved image was corrupted - when viewed in Opera, it looks like a capture of a part of the screen, not a part of the input image. This is also quite expensive.
Today will try other links you posted
it didn't work. When I tried to register vic32.dll, an error like 'DLLRegisterServer entry point not found' was displayed (i run w2k pro sp1).
I tried to save gif as gif, bmp as gif/jpg and jpg as jpg, but in all cases the saved image was corrupted - when viewed in Opera, it looks like a capture of a part of the screen, not a part of the input image. This is also quite expensive.
Today will try other links you posted
ASKER
I tried the example from freevbcode about saving .bmp as .gif - works, but the .gif quality is very bad compared to the input .bmp
It depends upon how many bit has bmp file, gif format allows only 256 colors.
That dll is no a COM dll, just plain dll, you have not to register it.
Let me know....
That dll is no a COM dll, just plain dll, you have not to register it.
Let me know....
What I'd do is load the image into a picturebox (or form) then move the pieces into a separate picturebox to be saved and repeat for all four pieces:
' Assum original picture is in picOriginal, and picTemp holds the piece
iRowCount=2
iColumnCount=2
For iRow=0 to iRowCount-1
For iColumn=0 to iColumnCount-1
iLeftStartPixel=iRow * picOriginal.width/iRowCoun t
iTopStartPixel=iColumn*pic Original.h eight/iCol umnCount
picTemp.Picture = LoadPicture("")
picTemp.PaintPicture picOriginal.Picture, 0,0,picOriginal.width/iRow Count, picOriginal.height/iColumn Count, iLeftStartPixel, iTopStartPixel
SaveImagePiece iRow *iColumnCount+iColumn
next iColumn
next iRow
...
Private sub SaveImagePiece(IDNumber as integer)
' This routine will store the picture in picTemp
' to store as a bitmap:
picTemp.SavePicture("PicPi ece" & IDNumber & ".bmp")
'
' For other formats, you'll need a special converter
end sub
' Assum original picture is in picOriginal, and picTemp holds the piece
iRowCount=2
iColumnCount=2
For iRow=0 to iRowCount-1
For iColumn=0 to iColumnCount-1
iLeftStartPixel=iRow * picOriginal.width/iRowCoun
iTopStartPixel=iColumn*pic
picTemp.Picture = LoadPicture("")
picTemp.PaintPicture picOriginal.Picture, 0,0,picOriginal.width/iRow
SaveImagePiece iRow *iColumnCount+iColumn
next iColumn
next iRow
...
Private sub SaveImagePiece(IDNumber as integer)
' This routine will store the picture in picTemp
' to store as a bitmap:
picTemp.SavePicture("PicPi
'
' For other formats, you'll need a special converter
end sub
Sorry..you need to put the clip size in the PaintPicture:
picTemp.PaintPicture picOriginal.Picture, 0,0, picOriginal.width/iRowCoun t, picOriginal.height/iColumn Count,iLef tStartPixe l, iTopStartPixel, 0,0, picOriginal.width/iRowCoun t, picOriginal.height/iColumn Count
picTemp.PaintPicture picOriginal.Picture, 0,0, picOriginal.width/iRowCoun
Hi rspahitz,
the problem is not spliting the image (it was already achieved)
The major problem is how to save splitted images in the same format as source image.
Peterned, i did use Vic32.dll and it works but, as i said, only for jpg format, i really don't know why doesn't works for gif.
the problem is not spliting the image (it was already achieved)
The major problem is how to save splitted images in the same format as source image.
Peterned, i did use Vic32.dll and it works but, as i said, only for jpg format, i really don't know why doesn't works for gif.
OK, Richie. However, I offered the preferred VB6 method for manipulating pictures: PatinPicture (which internally uses BitBlT but includes error-handling.) This also takes much less code and is therefore less subject to error.
peterned, i found location for vic32.dll:
http://www.catenary.com/download/vic5e.html
rspahitz, thats OK, it was done in another thread with code similar to yours.
http://www.catenary.com/download/vic5e.html
rspahitz, thats OK, it was done in another thread with code similar to yours.
Well, i have been trying with vic32.dll and get both files(Gif and JPG) from an image stored in a picture box Under windows 2000 with vb6 sp5
ASKER
well i still can't make vic32.dll to work.
I solved the problem to save pieces as jpg with intel's jpeg library ijl11.dll
but still can't find a way to save as gif. There is a working solution at freevbcode but the quality of the saved image is awful and seems there is no way to fix this
I solved the problem to save pieces as jpg with intel's jpeg library ijl11.dll
but still can't find a way to save as gif. There is a working solution at freevbcode but the quality of the saved image is awful and seems there is no way to fix this
Just remember that if source image is in 24 bit and you save it in gif format, quality degradation will happen.
Which is the problem with vic32.dll?
I just downloaded it and run it over w2k and images are saved without problem.
Which is the problem with vic32.dll?
I just downloaded it and run it over w2k and images are saved without problem.
ASKER
the problem is saved images can't be viewed anywhere but in Opera browser. In Opera, they look strange, least to say. In IE & NN they appear as red 'x'. Image editing apps like photoshop throw errors when trying to open such images.
I tried this on 3 PC's, so this is not a problem of a particular PC only
all the above is for vic32.dll, I'll not try anymore with it
this piece of code
http://www.freevbcode.com/ShowCode.Asp?ID=3533
can save whatever as gif, but with an auful quality. Any idea how to make it work better?
I tried this on 3 PC's, so this is not a problem of a particular PC only
all the above is for vic32.dll, I'll not try anymore with it
this piece of code
http://www.freevbcode.com/ShowCode.Asp?ID=3533
can save whatever as gif, but with an auful quality. Any idea how to make it work better?
Strange, i can open those images generated by vic with Paint shop pro and IE.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in Community Support that this question is:
- points to Richie_Simonetti
Please leave any comments here within the
next seven days.
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in Community Support that this question is:
- points to Richie_Simonetti
Please leave any comments here within the
next seven days.
per recommendation
SpideyMod
Community Support Moderator @Experts Exchange
SpideyMod
Community Support Moderator @Experts Exchange
seems to be very difficult.