Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Bitmap *bitmap = Bitmap::FromFile("XXXX",...);
- int width = bitmap->GetWidth();
- int height = bitmap->GetHeight();
- DrawImage(bitmap,0,0,width,height);
- SetStretchBltMode(hDC, COLORONCOLOR);
- StretchDIBits(hDC, rcDest.left, rcDest.top,
- rcDest.right-rcDest.left, rcDest.bottom-rcDest.top,
- 0, 0, width, height,
- BYTE* dib, dibinfo, DIB_RGB_COLORS, SRCCOPY);
- Bitmap bmp = new Bitmap(...)
- TextureBrush myBrush = new TextureBrush(bmp)
- private void Paint(object sender, PaintEventArgs e):
- {
- //Don't draw the bitmap directly.
- //Only draw TextureBrush inside the Paint event.
- e.Graphics.FillRectangle(myBrush, ...)
- }
- DrawImage(bitmap,0,0);
- DrawImage(bitmap, 0, 0, bitmap.GetWidth, bitmap.GetHeight);
- class procedure TGDIPlusHelper.DrawCachedBitmap(image: TGPImage;
- var cachedBitmap: TGPCachedBitmap;
- Graphics: TGPGraphics; x, y: Integer; width, height: Integer);
- var
- b: TGPBitmap;
- begin
- if (image = nil) then
- begin
- //i've chosen to not throw exceptions during paint code - it gets very nasty
- Exit;
- end;
- if (graphics = nil) then
- begin
- //i've chosen to not throw exceptions during paint code - it gets very nasty
- Exit;
- end;
- //Check if we have to invalidate the cached image because of size mismatch
- //i.e. if the user has "zoomed" the UI
- if (CachedBitmap <> nil) then
- begin
- if (CachedBitmap.BitmapWidth <> width) or (CachedBitmap.BitmapHeight <> height) then
- FreeAndNil(CachedBitmap); //nil'ing it will force it to be re-created down below
- end;
- //Check if we need to create the "cached" version of the bitmap
- if CachedBitmap = nil then
- begin
- b := TGDIPlusHelper.ResizeImage(image, width, height);
- try
- CachedBitmap := TGPCachedBitmap.Create(b, graphics);
- finally
- b.Free;
- end;
- end;
- if (graphics.DrawCachedBitmap(cachedBitmap, x, y) <> Ok) then
- begin
- //The calls to DrawCachedBitmap failed
- //The API is telling us we have to recreate the cached bitmap
- FreeAndNil(cachedBitmap);
- b := TGDIPlusHelper.ResizeImage(image, width, height);
- try
- CachedBitmap := TGPCachedBitmap.Create(b, graphics);
- finally
- b.Free;
- end;
- graphics.DrawCachedBitmap(cachedBitmap, x, y);
- end;
- end;
- Image imgPrintInvoice = new Image.FromFile("printer.png");
- CachedBitmap imgPrintInvoiceCached = null;
- ...
- int glyphSize = 16 * (GetCurrentDpi() / 96);
- DrawCachedBitmap(imgPrintInvoice , ref imgPrintInvoiceCached , graphics,
- 0, 0, glyphSize, glyphSize);
Add Comment
Please, Sign In to add comment