I have a c++ application that outputs text using SetBkMode:
wndDC=GetDC(wnd->getWnd());// hdc основного окна
watermark=CreateCompatibleDC(wndDC);// hdc текста
HBITMAP RAWwatermarkHbm=CreateCompatibleBitmap(wndDC,watermarkRectRAW.right,watermarkRectRAW.bottom);// HBITMAP для сырого текста
SelectObject(watermark,RAWwatermarkHbm);
SetBkMode(watermark,TRANSPARENT);
SetTextColor(watermark,RGB(150,150,150));
DrawText (watermark,watermarkText,-1,&textRect,DT_LEFT);
...
AlphaBlend(wndDC,watermarkRect.left,watermarkRect.top,watermarkRect.right,watermarkRect.bottom,
watermark,watermarkRectRAW.left,watermarkRectRAW.top,watermarkRectRAW.right,watermarkRectRAW.bottom,
this->bf);
wndDC and watermark are public fields of the class.
the text is first drawn in hdc watermark, and then in the hdc of the main window using AlphaBlend. Everything works fine on my PC, but if I run it on a laptop, the background turns black
I collect on mingw under windows
Related
I'm trying to load and draw an icon from an .ICO file that contains multiple icons. I can't figure out how to load a specific icon. I'm using LoadImage as in the following code
{
char *iconfile="myicon.ico";
int w=72,h=72;
hIcon = LoadImage( hMainInst, iconfile, IMAGE_ICON, w, h, LR_LOADFROMFILE );
}
This works Ok but the only way I can see to select a specific icon is by size, e.g., 72x72 in my example. It seems to load the first 72x72 icon in the file. The problem is that there are multiple 72x72 icons in the file.
How do I load an icon other than the first?
I'm new in programming a Win32 program. I want to display a tif image in the window, but I only found ways to display bitmap image. Does anyone got idea about how to display a tif image? Thanks.
Use Gdiplus::Bitmap class to load TIFF image. Then, get HBITMAP from it by calling GetHBITMAP.
I am working on a windows Phone app that can read Album arts dynamically from Music files through MediaPlayer APIs. I wish to get album arts and resize for view's background. Since the resize would lose details and make image ugly so I would like to blur it or some kind of effect. Is there any API that I can blur the image? (either from C# or XAML)? Thanks a lot!
I would start by using WriteableBitmap instead, to get a WriteableBitmap from a BitmapImage you can do the following:
WriteableBitmap wb = new WriteableBitmap(bitmapImage);
Then I would recommend using the WriteableBitmapExtension library. It has support for resizing the image:
wb.Resize(newWidth, newHeight, WriteableBitmapExtensions.Interpolation.Bilinear);
To do the gaussian blur with WritableBitmapExtensions do the following (for some reason concolution doesn't edit the writableBitmap, so you have to assign it again to the same writableBitmap to see the result):
wb = wb.Convolute(WriteableBitmapExtensions.KernelGaussianBlur5x5);
or
wb = wb.Convolute(WriteableBitmapExtensions.KernelGaussianBlur3x3);
(Just different weights for the neighbouring pixels).
How can I programatically set the lock screen image in Windows Phone 7? If this is not possible how can I add an image to the camera roll programatically?
Don't think you can do this directly, but you can save the image to the user's picture
library where the user could then choose to use the image for their lock screen image:
Photos, Photos, Photos - How To Save, Load And Iterate Pictures With Windows Phone 7
// Saves the WriteableBitmap encoded as JPEG to the Media library.
// The quality for JPEG encoding has to be in the range 0-100,
// where 100 is the best quality with the largest size.
void SaveToMediaLibrary(this WriteableBitmap bitmap, string name, int quality);
// Saves the WriteableBitmap encoded as JPEG to the Media library
// using the best quality of 100.
void SaveToMediaLibrary(this WriteableBitmap bitmap, string name);
I don't know if you can set the lock screen image programmatically. But in Windows Phone OS 7.1 ("Mango"), you can use the PhotoCamera class to programmatically access the camera and save the captured image to the Camera Roll folder using the SavePictureToCameraRoll method. Complete details are in the following topic:
How to: Create a Base Camera Application for Windows Phone
But basically, just create a method to fire after the capture is completed and wire-up the event-handler for it. If you're fine saving a JPEG, you can just write the stream right to the library.
This code shows initalizing the camera, wiring up an event handler, and applying the camera feed to a rectangle object on the page named vewfinderBrush:
//Code for initialization, image availability events anbd setting the source for the viewfinder
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
// Initialize camera
cam = new Microsoft.Devices.PhotoCamera();
// Event is fired when the capture sequence is complete and an image is available.
cam.CaptureImageAvailable += new EventHandler<Microsoft.Devices.ContentReadyEventArgs>(cam_CaptureImageAvailable);
//Set the VideoBrush source to the camera.
viewfinderBrush.SetSource(cam);
}
The photoCamera class makes two images available when it does a capture: the full image and a thumbnail. You can access the image both ways - using the ContentReadyEventArgs argument named e. If you handle the CaptureImageAvailable event, you get the full image. If you capture the CaptureThumbnailAvailable, you get the thumbnail.
// Informs when full resolution picture has been taken, saves to local media library void cam_CaptureImageAvailable(object sender, Microsoft.Devices.ContentReadyEventArgs e)
{
try
{
// Save picture to the device media library.
library.SavePictureToCameraRoll(fileName, e.ImageStream);
}
finally
{
// Close image stream
e.ImageStream.Close();
}
Note that the documentation also shows writing the image and thumbnail to isolated storage.
Hope that helps. Cheers
I've got a handle to a BITMAP structure (HBITMAP) in a Windows Mobile application -- I'd like to save the bitmap as a PNG file, using the IImage interface if possible. (There's no BMP file in this situation, the BITMAP is only in memory).
It looks like I could use IImagingFactory's IImagingFactory::CreateImageEncoderToFile method to save the file but I think I'd first have to get the BITMAP converted into "IImage" format.
Any ideas on how to do this with native code?
Use CreateImageFromStream to read in your BITMAP data, that gives you an IImage.
Edit:
I did a little more research on this. There are a couple paths, but I think the easiest is to:
create a DIBSECTION and blit your bitmap to it.
Create a BitmapData instance pointing to the DIBSECTION for the image data.
Call CreateBitmapFromBuffer to generate an IBitmapImage interface
Push the IBitmapImage (which is an IImage) through your encoder.