Dim DataArr (0 To 3) As Byte, pDataArr (0 To 0) As Long
GdipLoadImageFromFile StrConv (picFile vbUnicode), img 'image file picFile read
in the imgGdipGetImageBounds img, Dimensions, UnitPixel 'img image file size, save into Dimensions structure
Rct. Right=Dimensions. NWidth
Rct. Bottom=Dimensions. NHeight
GdipBitmapLockBits img, Rct, ImageLockModeRead PixelFormat, BmpData 'read image data
MakePoint VarPtrArray (DataArr), VarPtrArray (pDataArr), OldArrPtr, OldpArrPtr 'analog pointer
PDataArr (0)=BmpData. Scan0 'image in memory the first address
PixelAddBytes=IIf (PixelFormat=PixelFormat32bppRGB, 4, 3) 'each pixel of the number of bytes occupied
LineAddBytes=BmpData. Stride - BmpData. Width * PixelAddBytes' extra bytes in each scan line, do not need to deal with the
For Y=1 To BmpData. Height 'scanned from top To bottom
For X=1 To BmpData. Width from left To right scan
'DataArr (0)=255 'specific algorithm, DataArr (2)=r, DataArr (1)=g, DataArr (0)=b, the RGB values of pixels in a particular processing, can achieve the result of a particular new images, such as all kinds of filters, the color, black and white, blurred effect, specific pixel processing algorithm is the high-tech
DataArr (1)=255
DataArr (2)=255
Next
PDataArr (0)=pDataArr (0) + LineAddBytes' a starting position to the next scan line
Next
FreePoint VarPtrArray (DataArr), VarPtrArray (pDataArr), OldArrPtr OldpArrPtr 'release simulation pointer
GdipBitmapUnlockBits img BmpData 'update data
Pic. Picture=Loadpicture (" ")
PIC. Width=BmpData. Height - 100
PIC. Height=BmpData. Height - 100
GdipCreateFromHDC Pic. HDC, graphics' picture box DC image is drawn in, when the size of the Pic is too big, Pic. HDC become unable to create autoredraw object, failed, then how to create a memory HDC equipment? Then plotted on a memory dc new image, rather than through the picture frame to transfer, then how to save memory HDC draw good image as a file?
GdipDrawImageRectRectI graphics, img, 0, 0, BmpData. Width - 100, BmpData. Height - 100, 100, 100, BmpData. Width - 100, BmpData. Height - 100, UnitPixel 'will be the starting point of the original image img coordinates (100100), intercepting BmpData. Width - 100, BmpData. New areas of the image Height - 100
GdipDeleteGraphics graphics
Pic. Refresh 'to Refresh
SavePicture a, "C: \ Out. JPG" 'save the new image, the problem here, when the size of the PIC is too big, such as more than 567 pixels, PIC. HDC become unable to create autoredraw object, therefore, how to don't by PIC. HDC, but through the way of memory HDC, directly to the img image is copied to the specified area of the HDC in memory, and then directly to save the memory the new image as a file, and transit through picture box?
GdipDisposeImage img 'destruction of GDI + objects
GdiplusShutdown Token 'close the GDI +
CodePudding user response:
No master grant instruction?CodePudding user response:
This is GDI + very not...GDI with GetBitmapBits and GetObject bitmap data and bitmap information (data refers to the color of each pixel, information refers to such things as wide and high),
And then in turn to write BITMAPFILEHEADER file, BITMAPINFOHEADER and bitmap data...
GDI + didn't research can't jump to conclusions
CodePudding user response:
Can use the SaveAsFile IPicture interface method, the specific code oneself baidu,