Thanks Paul; that's exactly what I was looking for!!
Jose, thanks for the heads up... I didn't know about that function. But in the end, for what I'm doing, it's better to change the file and then lock it in my program so it doesn't get rotated again (because of the way I'm using it in my app).
Announcement
Collapse
No announcement yet.
Rotating Bitmap Without Window
Collapse
X
-
Jim,
you don't need to use createcompatiblebitmap at all if you don't want to display the bitmap, just load the bitmap directly into your own array, manipulate it and write it back to disk.
The following program is a quick demo, you'll need to tidy it up. It loads the bitmap specified, rotates it and writes it back to disk.
Paul.
Code:'PBCC4.0 program#COMPILE EXE TYPE BITMAPfile signature AS WORD SIZE AS LONG reserved1 AS WORD reserved2 AS WORD offset AS LONG sizeofheader AS LONG WIDTH AS LONG height AS LONG planes AS WORD bitsperpixel AS WORD compression AS LONG sizeofimage AS LONG horizres AS LONG vertres AS LONG colours1 AS LONG colours2 AS LONG END TYPE TYPE bit24 red AS BYTE blue AS BYTE green AS BYTE END TYPE FUNCTION PBMAIN () AS LONG ff&=FREEFILE OPEN "c:/test93.bmp" FOR BINARY AS ff& DIM mybitmap AS BITMAPfile GET ff&,,mybitmap 'assume a 24 bit colour bitmap DIM bitmapdata(1 TO mybitmap.width,1 TO mybitmap.height) AS bit24 DIM bitmapdataNew(1 TO mybitmap.width,1 TO mybitmap.height) AS bit24 GET ff&,mybitmap.offset,bitmapdata() 'get the bitmap data angle##=20 'degrees angle##=angle##/(180/3.141592653589) 'convert to radians 'rotate it FOR x&=1 TO mybitmap.width FOR y& = 1 TO mybitmap.height oldx&=x&*COS(angle##) + y&*SIN(angle##) oldy&=y&*COS(angle##) - x&*SIN(angle##) IF oldx&>0 AND oldx& < mybitmap.width AND oldy&>0 AND oldy&< mybitmap.height THEN bitmapdataNew(x&,y&) = bitmapdata(oldx&,oldy&) END IF NEXT NEXT PUT ff&, mybitmap.offset, bitmapdataNew() 'write new data back to bitmap CLOSE ff& END FUNCTION
Leave a comment:
-
-
Just seems I don't have the bandwidth to play with my PowerBasic, however, here are a couple of articles that I think would point you in the right direction...
Rotating a bitmap in memory: http://www.codeguru.com/cpp/g-m/gdi/article.php/c3693/
Saving memDC to file: http://www.codeguru.com/cpp/g-m/bitm...cle.php/c1741/
HTH
Regards,
Jules
Leave a comment:
-
-
The problem is that I'm not using graphic attach - I'm doing absolutely nothing with the bitmap besides rotating the FILE.
The reason I'm attempting this is that I have the image open in gdiplus, and I can't find any way to rotate a graphic using gdiplus, and I'm not sure that would be as accurate as rotating the file itself. The files I'm attempting to rotate are very large, so I'm concerned about keeping the quality intact.
Leave a comment:
-
-
If you use GRAPHIC ATTACH to do anything to the loaded bitmap, you should be able to use GRAPHIC GET DC to get the device context for that bitmap.
Also - for the bitmaps creates with the GRAPHIC statements, you may want to use GRAPHIC BITMAP END instead of DeleteObject.
Leave a comment:
-
-
Rotating Bitmap Without Window
I'm new to all this graphic stuff (never needed it til now) and I'm trying to rotate a bitmap without displaying it on a window...
The code below doesn't work because the bitblt is looking for a device context and I'm giving it a bitmap handle, but I'm not sure how to duplicate bitblt without a window. Any ideas???
Also, how do you save a handle of a memory bitmap to a disk file?
Code:function rotatedrawing(byval namefile$,byval ldegrees&) ff&=freefile open namefile$ for binary as #ff& base=0 seek #ff&,18 get$ #ff&,8,b$ close #ff& lwidth&=cvl(left$(b$,4)) lheight&=cvl(right$(b$,4)) graphic bitmap load namefile$,lwidth&,lheight& to hbmp& 'compute the radians from the input degrees lradians&=(3.14159)*ldegrees&/180 ' compute the sine/cosinse of the radians used to ' rotate this image lsine&=sin(lradians&) lcosine&=cos(lradians&) ' compute the size of the new bitmap being created x1&=-lheight&*lsine& y1&=lheight&*lcosine& x2&=lwidth&*lcosine&-lheight&*lsine& y2&=lheight&*lcosine&+lwidth&*lsine& x3&=lwidth&*lcosine& y3&=lwidth&*lsine& ' figure out the max/min size of the new bitmap lminx&=min(0,min(x1&,min(x2&,x3&))) lminy&=min(0,min(y1&,min(y2&,y3&))) lmaxx&=max(x1&,max(x2&,x3&)) lmaxy&=max(y1&,max(y2&,y3&)) ' set the new bitmap width/height lnewwidth&=lmaxx&-lminx& lnewheight&=lmaxy&-lminy& ''create a new bitmap based upon the new rotated bitmap hnewbmp&=createcompatiblebitmap(hbmp&,lnewwidth&,lnewheight&) ''translate each pixel to its new location using standard ''rotation algorithm for i&=0 to lnewheight& for j&=0 to lnewwidth& lsourcex&=(j&+lminx&)*lcosine&+(i&+lminy&)*lsine& lsourcey&=(i&+lminy&)*lcosine&-(j&+lminx&)*lsine& if (lsourcex&=>0) and (lsourcex&<=lwidth&) _ and (lsourcey&=>0) and (lsourcey&<=lheight&) then bitblt(hnewbmp&,j&,i&,1,1,hbmp&, _ lsourcex&,lsourcey&,%srccopy) end if next j& next i& ''lwidth&=lnewwidth& ''lheight&=lnewheight& deleteobject hbmp& ''how do I save hnewbmp& to namefile$ ??? deleteobject hnewbmp& function=1 end function
Tags: None
-
Leave a comment: