GVKun编程网logo

Delphi利用Windows GDI实现文字倾斜(delphi字体)

9

这篇文章主要围绕Delphi利用WindowsGDI实现文字倾斜和delphi字体展开,旨在为您提供一份详细的参考资料。我们将全面介绍Delphi利用WindowsGDI实现文字倾斜的优缺点,解答de

这篇文章主要围绕Delphi利用Windows GDI实现文字倾斜delphi字体展开,旨在为您提供一份详细的参考资料。我们将全面介绍Delphi利用Windows GDI实现文字倾斜的优缺点,解答delphi字体的相关问题,同时也会为您带来Android自定义TextView实现文字倾斜效果、BCB和Delphi添加Windows服务的描述性文字、Delphi 2007 x Windows 10 - 打开项目时出错 (Delphi 2007 x Windows 10 - Error on opening project)、Delphi 2007使用Windows Imaging Component(WIC)的实用方法。

本文目录一览:

Delphi利用Windows GDI实现文字倾斜(delphi字体)

Delphi利用Windows GDI实现文字倾斜(delphi字体)

总结

以上是小编为你收集整理的Delphi利用Windows GDI实现文字倾斜全部内容。

如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。

Android自定义TextView实现文字倾斜效果

Android自定义TextView实现文字倾斜效果

前言

由于Android自带的TextView控件没有提供倾斜的(我暂时没有找到),我们可以自定义控件来实现,下面首先来看我们实现的效果图。


TextView文字倾斜

其实实现很简单,下面我们来看实现步骤:

1、新建一个类 LeanTextView继承TextView

public class LeanTextView extends TextView {
  public int getmdegrees() {
    return mdegrees;
  }

  public void setmdegrees(int mdegrees) {
    this.mdegrees = mdegrees;
    invalidate();
  }

  private int mdegrees;

  public LeanTextView(Context context) {
    super(context,null);
  }

  public LeanTextView(Context context,AttributeSet attrs) {
    super(context,attrs,android.R.attr.textViewStyle);
    this.setGravity(Gravity.CENTER);
    TypedArray a = context.obtainStyledAttributes(attrs,R.styleable.LeanTextView);
    mdegrees = a.getDimensionPixelSize(R.styleable.LeanTextView_degree,0);
    a.recycle();
  }

  @Override
  protected void onMeasure(int widthMeasureSpec,int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec,heightMeasureSpec);
    setMeasuredDimension(getMeasuredWidth(),getMeasuredWidth());
  }

  @Override
  protected void onDraw(Canvas canvas) {
    canvas.save();
    canvas.translate(getCompoundPaddingLeft(),getExtendedPaddingTop());
    canvas.rotate(mdegrees,this.getWidth() / 2f,this.getHeight() / 2f);
    super.onDraw(canvas);
    canvas.restore();
  }
}

2、在values文件中新建styleable.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <declare-styleable name="LeanTextView">
    <attr name="degree" format="dimension" />
  </declare-styleable>
</resources>

3、页面布局,引用自定义控件

  <com.aikaifa.LeanTextView
    android:id="@+id/lean"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="10dp"
    android:text="爱开发" />

这里我们用TextView记录倾斜的角度,用SeekBar动态改变角度

  <com.aikaifa.LeanTextView
    android:id="@+id/lean"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="10dp"
    android:text="爱开发" />

  <TextView
    android:id="@+id/degrees"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="10dp"
    android:gravity="center"/>

  <SeekBar
    android:id="@+id/sb_lean"
    android:layout_width="match_parent"
    android:layout_marginTop="20dp"
    android:layout_height="wrap_content"
    android:max="100"
    android:progress="30" />

java代码

    mText= (LeanTextView) findViewById (R.id.lean);
    degrees= (TextView) findViewById (R.id.degrees);
    SeekBar sbLean = (SeekBar) findViewById(R.id.sb_lean);
    sbLean.setonSeekBarchangelistener(new SeekBar.OnSeekBarchangelistener() {
      @Override
      public void onProgressChanged(SeekBar seekBar,int progress,boolean fromUser) {
        mText.setmdegrees(progress);
        degrees.setText("倾斜度:"+progress);
      }

      @Override
      public void onStartTrackingTouch(SeekBar seekBar) {

      }

      @Override
      public void onStopTrackingTouch(SeekBar seekBar) {

      }
    });

这样关于TextView 文字倾斜的自定义控件就算基本完成了,是不是很简单。

项目结构图:


TextView文字倾斜项目结构图

总结

以上就是这篇文章的全部内容了,希望本文的内容对各位Android开发者们能有所帮助,如果有疑问大家可以留言交流。

BCB和Delphi添加Windows服务的描述性文字

BCB和Delphi添加Windows服务的描述性文字

总结

以上是小编为你收集整理的BCB和Delphi添加Windows服务的描述性文字全部内容。

如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。

Delphi 2007 x Windows 10 - 打开项目时出错 (Delphi 2007 x Windows 10 - Error on opening project)

Delphi 2007 x Windows 10 - 打开项目时出错 (Delphi 2007 x Windows 10 - Error on opening project)

问题:

Just updated from Windows 8.1 to Windows 10 and now when I try to open any project on Delphi 2007, I get his error :

Unable to load project xxxxx The imported project "c:\Windows\Microsft.NET...\Borland.Delphi.Targets" was not found. Confirm that the path declaration is correct, and that file exists on disk

查找需拷贝的文件路径:

在 C:\Windows.old 目录下搜索 Borland.Common.Targets 就能找到该文件所在路径。

解决方案:

You need to copy some files in your old Windows folder to the new one. After that projects open again.

The needed files are these :

c:\windows\Microsoft.NET\Framework\v2.0.50727\Borland.Common.Targets
c:\windows\Microsoft.NET\Framework\v2.0.50727\Borland.Cpp.Targets
c:\windows\Microsoft.NET\Framework\v2.0.50727\Borland.Delphi.Targets
c:\windows\Microsoft.NET\Framework\v2.0.50727\Borland.Group.Targets

Delphi 2007使用Windows Imaging Component(WIC)

Delphi 2007使用Windows Imaging Component(WIC)

我需要在Delphi 2007中阅读并将一些图片从jpg转换为bmb到bmp.

转换后,某些图片被剪切,灰度或最差.

我搜索过,但在任何情况下我都找不到在delphi 2007中添加像TWICImage这样的WIC例程的技巧.

我在某处读到可以通过COM轻松添加,但我不知道如何导入文件或文件.

谢谢.

解决方法

以下是如何使用WIC将JPEG转换为位图的示例:

unit Unit1;

interface

uses
  Windows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms,StdCtrls,Dialogs,ComObj,ActiveX;

const
  WICBitmapCacheOnLoad = $2;
  WICDecodeMetadataCacheondemand = 0;

  SID_Ipropertybag2 = '{22F55882-280B-11d0-A8A9-00A0C90C2004}';
  SID_IWICComponentInfo = '{23BC3F0A-698B-4357-886B-F24D50671334}';
  SID_IWICBitmapSource = '{00000120-a8f2-4877-ba0a-fd2b6645fb94}';
  SID_IWICBitmap = '{00000121-a8f2-4877-ba0a-fd2b6645fb94}';
  SID_IWICBitmapLock = '{00000123-a8f2-4877-ba0a-fd2b6645fb94}';
  SID_IWICBitmapCodecInfo = '{E87A44C4-B76E-4c47-8B09-298EB12A2714}';
  SID_IWICBitmapEncoder = '{00000103-a8f2-4877-ba0a-fd2b6645fb94}';
  SID_IWICBitmapDecoder = '{9EDDE9E7-8DEE-47ea-99DF-E6FAF2ED44BF}';
  SID_IWICBitmapEncoderInfo = '{94C9B4EE-A09F-4f92-8A1E-4A9BCE7E76FB}';
  SID_IWICBitmapDecoderInfo = '{D8CD007F-D08F-4191-9BFC-236EA7F0E4B5}';
  SID_IWICBitmapFrameEncode = '{00000105-a8f2-4877-ba0a-fd2b6645fb94}';
  SID_IWICBitmapFrameDecode = '{3B16811B-6A43-4ec9-A813-3D930C13B940}';
  SID_IWICBitmapScaler = '{00000302-a8f2-4877-ba0a-fd2b6645fb94}';
  SID_IWICBitmapClipper = '{E4FBCF03-223D-4e81-9333-D635556DD1B5}';
  SID_IWICBitmapFliprotator = '{5009834F-2D6A-41ce-9E1B-17C5AFF7A782}';
  SID_IWICPalette = '{00000040-a8f2-4877-ba0a-fd2b6645fb94}';
  SID_IWICColorContext = '{3C613A02-34B2-44ea-9A7C-45AEA9C6FD6D}';
  SID_IWICColorTransform = '{B66F034F-D0E2-40ab-B436-6DE39E321A94}';
  SID_IWICMetadataQueryReader = '{30989668-E1C9-4597-B395-458EEDB808DF}';
  SID_IWICMetadataQueryWriter = '{A721791A-0DEF-4d06-BD91-2118BF1DB10B}';
  SID_IWICFastMetadataEncoder = '{B84E2C09-78C9-4AC4-8BD3-524AE1663A2F}';
  SID_IWICStream = '{135FF860-22B7-4ddf-B0F6-218F4F299A43}';
  SID_IWICFormatConverter = '{00000301-a8f2-4877-ba0a-fd2b6645fb94}';
  SID_IWICImagingFactory = '{ec5ec8a9-c395-4314-9c77-54d7a935ff70}';
  CLSID_WICImagingFactory: TGUID = '{CACAF262-9370-4615-A13B-9F5539DA4C0A}';
  GUID_WICPixelFormat32bppBGRA: TGUID = '{6FDDC324-4E03-4BFE-B185-3D77768DC90F}';

type
  PWICColor = ^TWicColor;
  TWICColor = Cardinal;
  PWICRect = ^TWICRect;
  TWICRect = record
    X: Integer;
    Y: Integer;
    Width: Integer;
    Height: Integer;
  end;
  PIWICColorContext = ^IWICColorContext;
  PWICBitmapPattern = ^TWICBitmapPattern;
  TWICBitmapPattern = record
    Position: ULARGE_INTEGER;
    Length: ULONG;
    Pattern: PByte;
    Mask: PByte;
    EndOfStream: BOOL;
  end;
  PPropBag2 = ^TPropBag2;
  TPropBag2 = record
    dwType: DWORD;
    vt: tvarType;
    cfType: TClipformat;
    dwHint: DWORD;
    pstrName: POleStr;
    clsid: TCLSID;
  end;
  TWICInProcPointer = ^Byte;
  TWICPixelFormatGUID = TGUID;
  TREFWICPixelFormatGUID = PGUID;
  TWICComponentType = type Integer;
  TWICDecodeOptions = type Integer;
  TWICColorContextType = type Integer;
  TWICBitmapDitherType = type Integer;
  TWICBitmapPaletteType = type Integer;
  TWICBitmapInterpolationMode = type Integer;
  TWICBitmapEncoderCacheOption = type Integer;
  TWICBitmapTransformOptions = type Integer;
  TWICBitmapCreateCacheOption = type Integer;
  TWICBitmapAlphaChannelOption = type Integer;

  Ipropertybag2 = interface;
  IWICPalette = interface;
  IWICColorContext = interface;
  IWICColorTransform = interface;
  IWICBitmap = interface;
  IWICBitmapLock = interface;
  IWICBitmapSource = interface;
  IWICBitmapCodecInfo = interface;
  IWICBitmapEncoder = interface;
  IWICBitmapDecoder = interface;
  IWICBitmapEncoderInfo = interface;
  IWICBitmapDecoderInfo = interface;
  IWICBitmapFrameEncode = interface;
  IWICBitmapFrameDecode = interface;
  IWICBitmapScaler = interface;
  IWICBitmapClipper = interface;
  IWICBitmapFliprotator = interface;
  IWICMetadataQueryReader = interface;
  IWICMetadataQueryWriter = interface;
  IWICFastMetadataEncoder = interface;
  IWICStream = interface;
  IWICComponentInfo = interface;
  IWICFormatConverter = interface;
  IWICImagingFactory = interface;

  Ipropertybag2 = interface(IUnkNown)
    [SID_Ipropertybag2]
    function Read(pPropBag: PPropBag2; pErrLog: IErrorLog; pvarValue: PVariant; phrError: PHResult): HRESULT; stdcall;
    function Write(cProperties: ULONG; pPropBag: PPropBag2; pvarValue: PVariant): HRESULT; stdcall;
    function CountProperties(var pcProperties: ULONG): HRESULT; stdcall;
    function GetPropertyInfo(iProperty,cProperties: ULONG; pPropBag: PPropBag2; var pcProperties: ULONG): HRESULT; stdcall;
    function Loadobject(pstrName:POleStr; dwHint: DWORD; pUnkObject: IUnkNown; pErrLog: IErrorLog): HRESULT; stdcall;
  end;
  IWICComponentInfo = interface(IUnkNown)
    [SID_IWICComponentInfo]
    function GetComponentType(var pType: TWICComponentType): HRESULT; stdcall;
    function GetCLSID(var pclsid: TGUID): HRESULT; stdcall;
    function GetSigningStatus(var pStatus: DWORD): HRESULT; stdcall;
    function GetAuthor(cchAuthor: UINT; wzAuthor: PWCHAR; var pcchActual: UINT): HRESULT; stdcall;
    function GetvendorGUID(var pguidvendor: TGUID): HRESULT; stdcall;
    function GetVersion(cchVersion: UINT; wzVersion: PWCHAR; var pcchActual: UINT): HRESULT; stdcall;
    function GetSpecVersion(cchSpecVersion: UINT; wzSpecVersion: PWCHAR; var pcchActual: UINT): HRESULT; stdcall;
    function GetFriendlyName(cchFriendlyName: UINT; wzFriendlyName: PWCHAR; var pcchActual: UINT): HRESULT; stdcall;
  end;
  IWICBitmapSource = interface(IUnkNown)
    [SID_IWICBitmapSource]
    function GetSize(var puiWidth: UINT; var puiHeight: UINT): HRESULT; stdcall;
    function GetPixelFormat(var pPixelFormat: TWICPixelFormatGUID): HRESULT; stdcall;
    function GetResolution(var pDpiX: Double; var pDpiY: Double): HRESULT; stdcall;
    function copyPalette(pIPalette: IWICPalette): HRESULT; stdcall;
    function copyPixels(prc: PWICRect; cbStride: UINT; cbBufferSize: UINT; pbBuffer: PByte): HRESULT; stdcall;
  end;
  IWICBitmap = interface(IWICBitmapSource)
    [SID_IWICBitmap]
    function Lock(const prcLock: TWICRect; flags: DWORD; out ppILock: IWICBitmapLock): HRESULT; stdcall;
    function SetPalette(pIPalette: IWICPalette): HRESULT; stdcall;
    function SetResolution(dpiX: Double; dpiY: Double): HRESULT; stdcall;
  end;
  IWICBitmapLock = interface(IUnkNown)
    [SID_IWICBitmapLock]
    function GetSize(var puiWidth: UINT; var puiHeight: UINT): HRESULT; stdcall;
    function GetStride(var pcbStride: UINT): HRESULT; stdcall;
    function GetDataPointer(var pcbBufferSize: UINT; var ppbData: TWICInProcPointer): HRESULT; stdcall;
    function GetPixelFormat(var pPixelFormat: TWICPixelFormatGUID): HRESULT; stdcall;
  end;
  IWICBitmapCodecInfo = interface(IWICComponentInfo)
    [SID_IWICBitmapCodecInfo]
    function GetContainerFormat(var pguidContainerFormat: TGUID): HRESULT; stdcall;
    function GetPixelFormats(cFormats: UINT; var guidPixelFormats: PGUID; var pcActual: UINT): HRESULT; stdcall;
    function GetColorManagementVersion(cchColorManagementVersion: UINT; wzColorManagementVersion: PWCHAR; var pcchActual: UINT): HRESULT; stdcall;
    function GetDeviceManufacturer(cchDeviceManufacturer: UINT; wzDeviceManufacturer: PWCHAR; var pcchActual: UINT): HRESULT; stdcall;
    function GetDeviceModels(cchDeviceModels: UINT; wzDeviceModels: PWCHAR; var pcchActual: UINT): HRESULT; stdcall;
    function GetMimeTypes(cchMimeTypes: UINT; wzMimeTypes: PWCHAR; var pcchActual: UINT): HRESULT; stdcall;
    function GetFileExtensions(cchFileExtensions: UINT; wzFileExtensions: PWCHAR; var pcchActual: UINT): HRESULT; stdcall;
    function DoesSupportAnimation(var pfSupportAnimation: BOOL): HRESULT; stdcall;
    function DoesSupportChromakey(var pfSupportChromakey: BOOL): HRESULT; stdcall;
    function DoesSupportLossless(var pfSupportLossless: BOOL): HRESULT; stdcall;
    function DoesSupportMultiframe(var pfSupportMultiframe: BOOL): HRESULT; stdcall;
    function MatchesMimeType(wzMimeType: LPCWSTR; var pfMatches: BOOL): HRESULT; stdcall;
  end;
  IWICBitmapEncoder = interface(IUnkNown)
    [SID_IWICBitmapEncoder]
    function Initialize(pIStream: IStream; cacheOption: TWICBitmapEncoderCacheOption): HRESULT; stdcall;
    function GetContainerFormat(var pguidContainerFormat: TGUID): HRESULT; stdcall;
    function GetEncoderInfo(out ppIEncoderInfo: IWICBitmapEncoderInfo): HRESULT; stdcall;
    function SetColorContexts(cCount: UINT; ppIColorContext: PIWICColorContext): HRESULT; stdcall;
    function SetPalette(pIPalette: IWICPalette): HRESULT; stdcall;
    function SetThumbnail(pIThumbnail: IWICBitmapSource): HRESULT; stdcall;
    function SetPreview(pIPreview: IWICBitmapSource): HRESULT; stdcall;
    function CreateNewFrame(out ppIFrameEncode: IWICBitmapFrameEncode; var ppIEncoderOptions: Ipropertybag2): HRESULT; stdcall;
    function Commit: HRESULT; stdcall;
    function GetMetadataQueryWriter(out ppIMetadataQueryWriter: IWICMetadataQueryWriter): HRESULT; stdcall;
  end;
  IWICBitmapDecoder = interface(IUnkNown)
    [SID_IWICBitmapDecoder]
    function QueryCapability(pIStream: IStream; var pdwCapability: DWORD): HRESULT; stdcall;
    function Initialize(pIStream: IStream; cacheOptions: TWICDecodeOptions): HRESULT; stdcall;
    function GetContainerFormat(var pguidContainerFormat: TGUID): HRESULT; stdcall;
    function GetDecoderInfo(out ppIDecoderInfo: IWICBitmapDecoderInfo): HRESULT; stdcall;
    function copyPalette(pIPalette: IWICPalette): HRESULT; stdcall;
    function GetMetadataQueryReader(out ppIMetadataQueryReader: IWICMetadataQueryReader): HRESULT; stdcall;
    function GetPreview(out ppIBitmapSource: IWICBitmapSource): HRESULT; stdcall;
    function GetColorContexts(cCount: UINT; ppIColorContexts: PIWICColorContext; var pcActualCount : UINT): HRESULT; stdcall;
    function GetThumbnail(out ppIThumbnail: IWICBitmapSource): HRESULT; stdcall;
    function GetFrameCount(var pCount: UINT): HRESULT; stdcall;
    function GetFrame(index: UINT; out ppIBitmapFrame: IWICBitmapFrameDecode): HRESULT; stdcall;
  end;
  IWICBitmapEncoderInfo = interface(IWICBitmapCodecInfo)
    [SID_IWICBitmapEncoderInfo]
    function CreateInstance(out ppIBitmapEncoder: IWICBitmapEncoder): HRESULT; stdcall;
  end;
  IWICBitmapDecoderInfo = interface(IWICBitmapCodecInfo)
    [SID_IWICBitmapDecoderInfo]
    function GetPatterns(cbSizePatterns: UINT; pPatterns: PWICBitmapPattern; var pcPatterns: UINT; var pcbPatternsActual: UINT): HRESULT; stdcall;
    function MatchesPattern(pIStream: IStream; var pfMatches: BOOL): HRESULT; stdcall;
    function CreateInstance(out ppIBitmapDecoder: IWICBitmapDecoder): HRESULT; stdcall;
  end;
  IWICBitmapFrameEncode = interface(IUnkNown)
    [SID_IWICBitmapFrameEncode]
    function Initialize(pIEncoderOptions: Ipropertybag2): HRESULT; stdcall;
    function SetSize(uiWidth: UINT; uiHeight: UINT): HRESULT; stdcall;
    function SetResolution(dpiX: Double; dpiY: Double): HRESULT; stdcall;
    function SetPixelFormat(var pPixelFormat: TWICPixelFormatGUID): HRESULT; stdcall;
    function SetColorContexts(cCount: UINT; ppIColorContext: PIWICColorContext): HRESULT; stdcall;
    function SetPalette(pIPalette: IWICPalette): HRESULT; stdcall;
    function SetThumbnail(pIThumbnail: IWICBitmapSource): HRESULT; stdcall;
    function WritePixels(lineCount: UINT; cbStride: UINT; cbBufferSize: UINT; pbPixels: PByte): HRESULT; stdcall;
    function WriteSource(pIBitmapSource: IWICBitmapSource; prc: PWICRect): HRESULT; stdcall;
    function Commit: HRESULT; stdcall;
    function GetMetadataQueryWriter(out ppIMetadataQueryWriter: IWICMetadataQueryWriter): HRESULT; stdcall;
  end;
  IWICBitmapFrameDecode = interface(IWICBitmapSource)
    [SID_IWICBitmapFrameDecode]
    function GetMetadataQueryReader(out ppIMetadataQueryReader: IWICMetadataQueryReader): HRESULT; stdcall;
    function GetColorContexts(cCount: UINT; ppIColorContexts: PIWICColorContext; var pcActualCount : UINT): HRESULT; stdcall;
    function GetThumbnail(out ppIThumbnail: IWICBitmapSource): HRESULT; stdcall;
  end;
  IWICBitmapScaler = interface(IWICBitmapSource)
    [SID_IWICBitmapScaler]
    function Initialize(pISource: IWICBitmapSource; uiWidth: UINT; uiHeight: UINT; mode: TWICBitmapInterpolationMode): HRESULT; stdcall;
  end;
  IWICBitmapClipper = interface(IWICBitmapSource)
    [SID_IWICBitmapClipper]
    function Initialize(pISource: IWICBitmapSource; var prc: TWICRect): HRESULT; stdcall;
  end;
  IWICBitmapFliprotator = interface(IWICBitmapSource)
    [SID_IWICBitmapFliprotator]
    function Initialize(pISource: IWICBitmapSource; options: TWICBitmapTransformOptions): HRESULT; stdcall;
  end;
  IWICPalette = interface(IUnkNown)
    [SID_IWICPalette]
    function InitializePredefined(ePaletteType: TWICBitmapPaletteType; fAddTransparentColor: BOOL): HRESULT; stdcall;
    function InitializeCustom(pColors: PWICColor; cCount: UINT): HRESULT; stdcall;
    function InitializefromBitmap(pISurface: IWICBitmapSource; cCount: UINT; fAddTransparentColor: BOOL): HRESULT; stdcall;
    function InitializefromPalette(pIPalette: IWICPalette): HRESULT; stdcall;
    function GetType(var pePaletteType: TWICBitmapPaletteType): HRESULT; stdcall;
    function GetColorCount(var pcCount: UINT): HRESULT; stdcall;
    function GetColors(cCount: UINT; pColors: PWICColor; var pcActualColors: UINT): HRESULT; stdcall;
    function IsBlackWhite(var pfIsBlackWhite: BOOL): HRESULT; stdcall;
    function IsGrayscale(var pfIsGrayscale: BOOL): HRESULT; stdcall;
    function HasAlpha(var pfHasAlpha: BOOL): HRESULT; stdcall;
  end;
  IWICColorContext = interface(IUnkNown)
    [SID_IWICColorContext]
    function InitializefromFilename(wzFilename: LPCWSTR): HRESULT; stdcall;
    function InitializefromMemory(const pbBuffer: PByte; cbBufferSize: UINT): HRESULT; stdcall;
    function InitializefromExifColorSpace(value: UINT): HRESULT; stdcall;
    function GetType(var pType: TWICColorContextType): HRESULT; stdcall;
    function GetProfileBytes(cbBuffer: UINT; pbBuffer: PByte; var pcbActual: UINT): HRESULT; stdcall;
    function GetExifColorSpace(var pValue: UINT): HRESULT; stdcall;
  end;
  IWICColorTransform = interface(IWICBitmapSource)
    [SID_IWICColorTransform]
    function Initialize(pIBitmapSource: IWICBitmapSource; pIContextSource: IWICColorContext; pIContextDest: IWICColorContext; pixelFmtDest: TREFWICPixelFormatGUID): HRESULT; stdcall;
  end;
  IWICMetadataQueryReader = interface(IUnkNown)
    [SID_IWICMetadataQueryReader]
    function GetContainerFormat(var pguidContainerFormat: TGUID): HRESULT; stdcall;
    function GetLocation(cchMaxLength: UINT; wzNamespace: PWCHAR; var pcchActualLength: UINT): HRESULT; stdcall;
    function GetMetadataByName(wzName: LPCWSTR; var pvarValue: PROPVARIANT): HRESULT; stdcall;
    function GetEnumerator(out ppIEnumString: IEnumString): HRESULT; stdcall;
  end;
  IWICMetadataQueryWriter = interface(IWICMetadataQueryReader)
    [SID_IWICMetadataQueryWriter]
    function SetMetadataByName(wzName: LPCWSTR; const pvarValue: TPropVariant): HRESULT; stdcall;
    function RemoveMetadataByName(wzName: LPCWSTR): HRESULT; stdcall;
  end;
  IWICFastMetadataEncoder = interface(IUnkNown)
    [SID_IWICFastMetadataEncoder]
    function Commit: HRESULT; stdcall;
    function GetMetadataQueryWriter(out ppIMetadataQueryWriter: IWICMetadataQueryWriter): HRESULT; stdcall;
  end;
  IWICStream = interface(IStream)
    [SID_IWICStream]
    function InitializefromIStream(pIStream: IStream): HRESULT; stdcall;
    function InitializefromFilename(wzFileName: LPCWSTR; dwDesiredAccess: DWORD): HRESULT; stdcall;
    function InitializefromMemory(pbBuffer: TWICInProcPointer; cbBufferSize: DWORD): HRESULT; stdcall;
    function InitializefromIStreamRegion(pIStream: IStream; ulOffset: ULARGE_INTEGER; ulMaxSize: ULARGE_INTEGER): HRESULT; stdcall;
  end;
  IWICFormatConverter = interface(IWICBitmapSource)
    [SID_IWICFormatConverter]
    function Initialize(pISource: IWICBitmapSource; const dstFormat: TWICPixelFormatGUID; dither: TWICBitmapDitherType; const pIPalette: IWICPalette; alphaThresholdPercent: Double; paletteTranslate: TWICBitmapPaletteType): HRESULT; stdcall;
    function CanConvert(srcPixelFormat: TREFWICPixelFormatGUID; dstPixelFormat: TREFWICPixelFormatGUID; var pfCanConvert: BOOL): HRESULT; stdcall;
  end;
  IWICImagingFactory = interface(IUnkNown)
    [SID_IWICImagingFactory]
    function CreateDecoderFromFilename(wzFilename: LPCWSTR; const pguidvendor: TGUID; dwDesiredAccess: DWORD; MetadataOptions: TWICDecodeOptions; out ppIDecoder: IWICBitmapDecoder): HRESULT; stdcall;
    function CreateDecoderFromStream(pIStream: IStream; const pguidvendor: TGUID; MetadataOptions: TWICDecodeOptions; out ppIDecoder: IWICBitmapDecoder): HRESULT; stdcall;
    function CreateDecoderFromFileHandle(hFile: ULONG_PTR; const pguidvendor: TGUID; MetadataOptions: TWICDecodeOptions; out ppIDecoder: IWICBitmapDecoder): HRESULT; stdcall;
    function CreateComponentInfo(const clsidComponent: TGUID; out ppIInfo: IWICComponentInfo): HRESULT; stdcall;
    function CreateDecoder(const guidContainerFormat: TGUID; const pguidvendor: TGUID; out ppIDecoder: IWICBitmapDecoder): HRESULT; stdcall;
    function CreateEncoder(const guidContainerFormat: TGUID; const pguidvendor: TGUID; out ppIEncoder: IWICBitmapEncoder): HRESULT; stdcall;
    function CreatePalette(out ppIPalette: IWICPalette): HRESULT; stdcall;
    function CreateFormatConverter(out ppIFormatConverter: IWICFormatConverter): HRESULT; stdcall;
    function CreateBitmapScaler(out ppIBitmapScaler: IWICBitmapScaler): HRESULT; stdcall;
    function CreateBitmapClipper(out ppIBitmapClipper: IWICBitmapClipper): HRESULT; stdcall;
    function CreateBitmapFliprotator(out ppIBitmapFliprotator: IWICBitmapFliprotator): HRESULT; stdcall;
    function CreateStream(out ppIWICStream: IWICStream): HRESULT; stdcall;
    function CreateColorContext(out ppIWICColorContext: IWICColorContext): HRESULT; stdcall;
    function CreateColorTransformer(out ppIWICColorTransform: IWICColorTransform): HRESULT; stdcall;
    function CreateBitmap(uiWidth: UINT; uiHeight: UINT; pixelFormat: TREFWICPixelFormatGUID; option: TWICBitmapCreateCacheOption; out ppIBitmap: IWICBitmap): HRESULT; stdcall;
    function CreateBitmapFromSource(pIBitmapSource: IWICBitmapSource; option: TWICBitmapCreateCacheOption; out ppIBitmap: IWICBitmap): HRESULT; stdcall;
    function CreateBitmapFromSourceRect(pIBitmapSource: IWICBitmapSource; x: UINT; y: UINT; width: UINT; height: UINT; out ppIBitmap: IWICBitmap): HRESULT; stdcall;
    function CreateBitmapFromMemory(uiWidth: UINT; uiHeight: UINT; const pixelFormat: TWICPixelFormatGUID; cbStride: UINT; cbBufferSize: UINT; pbBuffer: PByte; out ppIBitmap: IWICBitmap): HRESULT; stdcall;
    function CreateBitmapFromHBITMAP(hBitmap: HBITMAP; hPalette: HPALETTE; options: TWICBitmapAlphaChannelOption; out ppIBitmap: IWICBitmap): HRESULT; stdcall;
    function CreateBitmapFromHICON(hIcon: HICON; out ppIBitmap: IWICBitmap): HRESULT; stdcall;
    function CreateComponentEnumerator(componentTypes: DWORD; options: DWORD; out ppIEnumUnkNown: IEnumUnkNown): HRESULT; stdcall;
    function CreateFastMetadataEncoderFromDecoder(pIDecoder: IWICBitmapDecoder; out ppIFastEncoder: IWICFastMetadataEncoder): HRESULT; stdcall;
    function CreateFastMetadataEncoderFromFrameDecode(pIFrameDecoder: IWICBitmapFrameDecode; out ppIFastEncoder: IWICFastMetadataEncoder): HRESULT; stdcall;
    function createqueryWriter(const guidMetadataFormat: TGUID; const pguidvendor: TGUID; out ppIQueryWriter: IWICMetadataQueryWriter): HRESULT; stdcall;
    function createqueryWriterFromreader(pIQueryReader: IWICMetadataQueryReader; const pguidvendor: TGUID; out ppIQueryWriter: IWICMetadataQueryWriter): HRESULT; stdcall;
  end;

  function WICConvertBitmapSource(const dstFormat: TWICPixelFormatGUID; pISrc: IWICBitmapSource; out ppIDst: IWICBitmapSource): HRESULT; stdcall;
    external 'windowscodecs.dll' name 'WICConvertBitmapSource';

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    FImagingFactory: IWICImagingFactory;
    procedure JpegToBitmap(const ASource,ATarget: string);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.JpegToBitmap(const ASource,ATarget: string);
var
  FileStream: TFileStream;
  StreamAdapter: TStreamAdapter;
  BitmapInfo: TBitmapInfo;
  BitmapBits: array of Byte;
  BitmapWidth: Cardinal;
  BitmapHeight: Cardinal;
  BitmapOutput: TBitmap;
  BitmapObject: IWICBitmap;
  BitmapSource: IWICBitmapSource;
  BitmapDecoder: IWICBitmapDecoder;
  BitmapFrame: IWICBitmapFrameDecode;
begin
  if not Assigned(FImagingFactory) then
    CoCreateInstance(CLSID_WICImagingFactory,nil,CLSCTX_INPROC_SERVER or
      CLSCTX_LOCAL_SERVER,IUnkNown,FImagingFactory);

  FileStream := TFileStream.Create(ASource,fmOpenRead or fmShareDenyWrite);
  try
    FileStream.Position := 0;
    StreamAdapter := TStreamAdapter.Create(FileStream);

    OleCheck(FImagingFactory.CreateDecoderFromStream(StreamAdapter,GUID_NULL,WICDecodeMetadataCacheondemand,BitmapDecoder));
    OleCheck(BitmapDecoder.GetFrame(0,BitmapFrame));
    OleCheck(FImagingFactory.CreateBitmapFromSource(BitmapFrame,WICBitmapCacheOnLoad,BitmapObject));
    OleCheck(BitmapObject.GetSize(BitmapWidth,BitmapHeight));
    SetLength(BitmapBits,BitmapWidth * BitmapHeight * 4);
    OleCheck(WICConvertBitmapSource(GUID_WICPixelFormat32bppBGRA,BitmapObject,BitmapSource));
    OleCheck(BitmapSource.copyPixels(nil,BitmapWidth * 4,Length(BitmapBits),@BitmapBits[0]));

    FillChar(BitmapInfo,SizeOf(BitmapInfo),0);
    BitmapInfo.bmiHeader.biSize := SizeOf(BitmapInfo);
    BitmapInfo.bmiHeader.biWidth := BitmapWidth;
    BitmapInfo.bmiHeader.biHeight := -BitmapHeight;
    BitmapInfo.bmiHeader.biPlanes := 1;
    BitmapInfo.bmiHeader.biBitCount := 32;

    BitmapOutput := TBitmap.Create;
    try
      BitmapOutput.PixelFormat := pf32bit;
      BitmapOutput.SetSize(BitmapWidth,BitmapHeight);
      SetDIBits(0,BitmapOutput.Handle,BitmapHeight,@BitmapBits[0],BitmapInfo,DIB_RGB_COLORS);
      BitmapOutput.AlphaFormat := afDefined;
      BitmapOutput.SavetoFile(ATarget);
    finally
      BitmapOutput.Free;
    end;
  finally
    FileStream.Free;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  JpegToBitmap('d:\SourceImage.jpg','d:\Targetimage.bmp');
end;

end.

我们今天的关于Delphi利用Windows GDI实现文字倾斜delphi字体的分享已经告一段落,感谢您的关注,如果您想了解更多关于Android自定义TextView实现文字倾斜效果、BCB和Delphi添加Windows服务的描述性文字、Delphi 2007 x Windows 10 - 打开项目时出错 (Delphi 2007 x Windows 10 - Error on opening project)、Delphi 2007使用Windows Imaging Component(WIC)的相关信息,请在本站查询。

本文标签: