本文介绍了Gdiplus抽绳到位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 嗨大家好, i尝试使用gdiplus创建字体位图,我正在使用抽象字符串和位图保存选项..它实际上应该在位图文件中保存一个字符相反它只是输出一个黑色填充的矩形......请在代码中告诉我Wats错误... i也尝试使用lockbits和unlockbits来绘制字符串。 。Hi folks, i am trying to create font bitmaps using gdiplus, am using drawstring and bitmap save option.. It should actually save a character in the bitmap file rather its just outputting a black filled rectangle... pls advice me wats wrong in the code...i have also tried using lockbits and unlockbits to draw a string..CString szFile;m_edtFile.GetWindowText(szFile);Gdiplus::Status nResults = m_fontcollection.AddFontFile(szFile);if (nResults != Gdiplus::Ok){ MessageBox(L"Font add fails", L"Error");}CPaintDC dc(this);using namespace Gdiplus;Gdiplus::Bitmap bitmap(L"C:\\Users\\dc230\\Desktop\\New folder\\map.bmp");Graphics graphics(dc.m_hDC);graphics.FromImage(&bitmap);graphics.SetSmoothingMode(SmoothingModeAntiAlias); //sets the rendering quality of the Graphics objectgraphics.SetTextRenderingHint(TextRenderingHintSingleBitPerPixelGridFit); //method to specify the type of antialiasing (if any) applied to textSolidBrush brush(Color(255,255,255));FontFamily fontFamily;int nNumFound=0;m_fontcollection.GetFamilies(1,&fontFamily,&nNumFound);if (nNumFound > 0){ Gdiplus::Font font(&fontFamily,28,FontStyleRegular,UnitPixel); StringFormat strformat; strformat.SetAlignment(StringAlignmentCenter); wchar_t buf[] = {L"A"}; RectF therect; therect.Height = 10; therect.Width = 10; therect.X = 5; therect.Y = 5; Gdiplus::Status st =graphics.DrawString(buf,wcslen(buf),&font,therect,&strformat,&brush); graphics.Save(); Gdiplus::Bitmap b(100,100,&graphics); graphics.FromImage(&b); Gdiplus::BitmapData bmpd= {}; Rect therect1; therect.Height = 50; therect.Width = 30; therect.X = 20; therect.Y = 10; bitmap.LockBits(&therect1, ImageLockModeWrite,PixelFormat32bppARGB,&bmpd); ::glTexImage2D( GL_TEXTURE_2D,0,GL_RGBA ,50,50,0,GL_RGBA,GL_BITMAP,0); bitmap.UnlockBits(&bmpd); // Rotate bitmap 180 degrees b.RotateFlip(Rotate180FlipNone); if (b.GetLastStatus() == Ok) { EncoderParameters pEncoderParameters; pEncoderParameters.Count = 1; pEncoderParameters.Parameter[0].Guid = EncoderCompression; pEncoderParameters.Parameter[0].Type = EncoderParameterValueTypeLong; pEncoderParameters.Parameter[0].NumberOfValues = 1; // Save the image as a bmp ULONG compression = EncoderValueCompressionRle; pEncoderParameters.Parameter[0].Value = &compression; CLSID encoderClsid; GetEncoderClsid(L"image/bmp", &encoderClsid); b.Save(L"C:\\Users\\dc230\\Desktop\\New folder\\map1.bmp",&encoderClsid, &pEncoderParameters); MessageBox(L"Image Got Saved !"); } else { MessageBox(L"Unable to save the bitmap"); }}推荐答案 这篇关于Gdiplus抽绳到位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-23 09:54