not really. hang on
Printable View
not really. hang on
The idea is that you call it before you do any stretching. It does work, not its not all that great ...
VB Code:
' StretchBlt() Modes Const BLACKONWHITE = 1 Const WHITEONBLACK = 2 Const COLORONCOLOR = 3 Const HALFTONE = 4 Private Declare Function SetStretchBltMode Lib "gdi32" (ByVal hdc As Long, ByVal nStretchMode As Long) As Long Private Sub Form_Load() SetStretchBltMode Picture1.hdc, HALFTONE End Sub
Is there anything you dont know? :)
ah im sure there's a few bits and pieces :)
ha ha very funny!!
Ok, I am doing an important project.
I need to allow the user to click on an image JPG or BMP
whatever they choose i want to resize (make smaller mostly) to make sure it is 489x489 pixels and then resave it as BMP or JPG
I was wondering if it was possible to use the IMAGE control to STRETCH (property) the picture so its square (489x489) and then copy the 489x489 pixels into a picturebox so i can use the SAVEPICTURE method on the picturebox.
Does this make sense?
It save calling StretchBlt etc.....
Hello Mr Jamie person
Do you know how easy it is to do this?
Yes, quite.
Gimme a few mins.
VB Code:
Option Explicit Private picDc As Long Private picWidth As Long Private picHeight As Long 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 LoadImage Lib "user32" Alias "LoadImageA" (ByVal hInst As Long, ByVal lpsz As String, ByVal un1 As Long, ByVal n1 As Long, ByVal n2 As Long, ByVal un2 As Long) As Long Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long Private Declare Function StretchBlt Lib "gdi32" (ByVal hdc 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 nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long Private Declare Function SetStretchBltMode Lib "gdi32" (ByVal hdc As Long, ByVal nStretchMode As Long) As Long ' StretchBlt() Modes Private Const BLACKONWHITE = 1 Private Const WHITEONBLACK = 2 Private Const COLORONCOLOR = 3 Private Const HALFTONE = 4 Private Const MAXSTRETCHBLTMODE = 4 Public Function GenerateDC(FileName As String) As Long Dim DC As Long, picTemp As IPictureDisp DC = CreateCompatibleDC(0) If DC < 1 Then Exit Function End If Set picTemp = LoadPicture(FileName) picWidth = ScaleX(picTemp.Width) picHeight = ScaleY(picTemp.Height) SelectObject DC, picTemp DeleteObject picTemp Set picTemp = Nothing GenerateDC = DC End Function Private Sub cmdDoodle_Click() With CommonDialog1 .ShowOpen If Not .FileName = "" Then Dim tempDc As Long picDc = GenerateDC(.FileName) If (picWidth > 489) Or (picHeight > 489) Then SetStretchBltMode Picture1.hdc, WHITEONBLACK StretchBlt Picture1.hdc, 0, 0, 489, 489, picDc, 0, 0, picWidth, picHeight, vbSrcCopy .ShowSave If Not .FileName = "" Then SavePicture Picture1.Image, .FileName MsgBox "Image saved" End If End If End If End With End Sub Private Sub Form_Load() ScaleMode = 3 With Picture1 .ScaleMode = 3 .Width = 489 .Height = 489 .AutoRedraw = True End With End Sub
Jamie,
You are the dogs bo******!!! It works fantastic!!!!
Had to make a couple of changes, including using the HALFTONE option but its fantastic!! All i need to do now is at some point look into converting the image to JPEG but at least my app works fine and the images are only 600K anyway. I can live with that!
If you were over here in sunny England and Id buy you all the beers you could drink. Thanks a lot mate....
I dont care what anyone else is saying about you, i think you are alright! :))
Yes I am joking so dont get paranoid!
Jamie,
One quick question..................The code doesnt ALWAYS work but I know why. The GenerateDC function sometimes returns zero (20% of the time). When the return value is zero the picture doesnt get saved or displayed. When its a positive Long, it does.
Why should this happen intermittently?
Should I 'while' it in a loop until the Return value is greater than zero?
I found that using WHITEONBLACK seemed to give better results, contradictory to documentation...
Um anyway regarding the GenerateDC() function. Hmm I've seen a few cases where its not perfect. I wrote the function myself, so perhaps there are better versions out there ?
Alternatively you could just add another picturebox, and use .LoadPicture to get an image into it, then stretchblt into the second picturebox
my name is dave ;)Quote:
Originally posted by Blobby
da_Silvy.....What is your real name? I cant keep calling you that!
Thanks for the info. Im a bit puzzled though.
It doesnt really say what the outcome was as some people had problems doing it the way suggested. All I can find in search engines are ActiveX/DLL's that you have to pay 100 bucks for.
It must be possible in that case so how come there is no code around to do it available for cut and paste?
I still have little information on whether it is actually possible at all.
Blob
Thanks for the contribution there dave ;)
no probs
what language is ur location in?
Gaeilge (Irish)
gaelic?
is that scottish?
Um basically the same I suppose